summaryrefslogtreecommitdiff
path: root/test/integration/targets/ec2_instance/roles/ec2_instance/tasks/main.yml
blob: e10aebcefe278f947849d0a2f123c7059fdc23f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
# Beware: most of our tests here are run in parallel.
# To add new tests you'll need to add a new host to the inventory and a matching
# '{{ inventory_hostname }}'.yml file in roles/ec2_instance/tasks/
#
#  Please make sure you tag your instances with
#     tags:
#       "tag:TestId": "{{ ec2_instance_tag_TestId }}"
#  And delete them based off that tag at the end of your specific set of tests
#
# ###############################################################################
#
# A Note about ec2 environment variable name preference:
#  - EC2_URL -> AWS_URL
#  - EC2_ACCESS_KEY -> AWS_ACCESS_KEY_ID -> AWS_ACCESS_KEY
#  - EC2_SECRET_KEY -> AWS_SECRET_ACCESS_KEY -> AWX_SECRET_KEY
#  - EC2_REGION -> AWS_REGION
#

- name: "Wrap up all tests and setup AWS credentials"
  module_defaults:
    group/aws:
      aws_access_key: "{{ aws_access_key }}"
      aws_secret_key: "{{ aws_secret_key }}"
      security_token: "{{ security_token | default(omit) }}"
      region: "{{ aws_region }}"
  block:
    - debug:
        msg: "{{ inventory_hostname }} start: {{ lookup('pipe','date') }}"
    - include_tasks: '{{ inventory_hostname }}.yml'
    - debug:
        msg: "{{ inventory_hostname }} finish: {{ lookup('pipe','date') }}"

  always:
    - set_fact:
        _role_complete: True
    - vars:
        completed_hosts: '{{ ansible_play_hosts_all | map("extract", hostvars, "_role_complete") | list | select("defined") | list | length }}'
        hosts_in_play: '{{ ansible_play_hosts_all | length }}'
      debug:
        msg: "{{ completed_hosts }} of {{ hosts_in_play }} complete"
    - include_tasks: env_cleanup.yml
      vars:
        completed_hosts: '{{ ansible_play_hosts_all | map("extract", hostvars, "_role_complete") | list | select("defined") | list | length }}'
        hosts_in_play: '{{ ansible_play_hosts_all | length }}'
      when:
      - aws_cleanup
      - completed_hosts == hosts_in_play