Debian Codegraph @

ansible_collections/community/aws/tests/integration/targets/setup_ec2_facts/tasks/main.yml

raw
1 ---
2 # Setup a couple of common facts about the AWS Region
3 #
4 # Information about availablity zones
5 # - ec2_availability_zone_names
6 #
7 # An EC2 AMI that can be used for spinning up Instances performs as search
8 # rather than hardcoding the IDs so we're not limited to specific Regions
9 # - ec2_ami_id
10 #
11 - name: Setup common EC2 related facts.
12 module_defaults:
13 group/aws:
14 access_key: "{{ aws_access_key }}"
15 secret_key: "{{ aws_secret_key }}"
16 session_token: "{{ security_token | default(omit) }}"
17 region: "{{ aws_region }}"
18
19 run_once: true
20 block:
21 # ============================================================
22
23 - name: Get available AZs
24 amazon.aws.aws_az_info:
25 filters:
26 region-name: "{{ aws_region }}"
27 register: _az_info
28
29 - name: Pick an AZ
30 ansible.builtin.set_fact:
31 ec2_availability_zone_names: '{{ _az_info.availability_zones | selectattr("zone_name", "defined") | map(attribute="zone_name") | list }}'
32
33 # ============================================================
34
35 - name: Get a list of images
36 amazon.aws.ec2_ami_info:
37 filters:
38 name: "{{ ec2_ami_name }}"
39 owner-id: "{{ ec2_ami_owner_id }}"
40 architecture: x86_64
41 virtualization-type: hvm
42 root-device-type: ebs
43 register: _images_info
44 # Very spammy
45 no_log: true
46
47 - name: Set Fact for latest AMI
48 vars:
49 latest_image: '{{ _images_info.images | sort(attribute="creation_date") | reverse | first }}'
50 ansible.builtin.set_fact:
51 ec2_ami_id: "{{ latest_image.image_id }}"
52 ec2_ami_details: "{{ latest_image }}"
53 ec2_ami_root_disk: "{{ latest_image.block_device_mappings[0].device_name }}"
54 ec2_ami_ssh_user: "{{ ec2_ami_ssh_user }}"