Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/ec2_eni/tasks/main.yaml

raw
1 ---
2 - module_defaults:
3 group/aws:
4 access_key: "{{ aws_access_key }}"
5 secret_key: "{{ aws_secret_key }}"
6 session_token: "{{ security_token | default(omit) }}"
7 region: "{{ aws_region }}"
8
9 block:
10 # ============================================================
11 - name: Create a VPC
12 amazon.aws.ec2_vpc_net:
13 name: "{{ resource_prefix }}-vpc"
14 state: present
15 cidr_block: "{{ vpc_cidr }}"
16 tags:
17 Name: "{{ resource_prefix }}-vpc"
18 Description: Created by ansible-test
19 register: vpc_result
20
21 - name: Create a subnet
22 amazon.aws.ec2_vpc_subnet:
23 cidr: "{{ vpc_cidr }}"
24 az: "{{ availability_zone }}"
25 vpc_id: "{{ vpc_result.vpc.id }}"
26 tags:
27 Name: "{{ resource_prefix }}-vpc"
28 Description: Created by ansible-test
29 state: present
30 register: vpc_subnet_result
31
32 - name: Create a security group
33 amazon.aws.ec2_security_group:
34 name: "{{ resource_prefix }}-sg"
35 description: Created by {{ resource_prefix }}
36 rules: []
37 state: present
38 vpc_id: "{{ vpc_result.vpc.id }}"
39 register: vpc_sg_result
40
41 - name: Set facts to simplify use of extra resources
42 ansible.builtin.set_fact:
43 vpc_id: "{{ vpc_result.vpc.id }}"
44 vpc_subnet_id: "{{ vpc_subnet_result.subnet.id }}"
45 vpc_sg_id: "{{ vpc_sg_result.group_id }}"
46
47 # ============================================================
48
49 - name: Create 2 instances to test attaching and detaching network interfaces
50 amazon.aws.ec2_instance:
51 name: "{{ resource_prefix }}-eni-instance-{{ item }}"
52 image_id: "{{ ec2_ami_id }}"
53 vpc_subnet_id: "{{ vpc_subnet_id }}"
54 instance_type: t2.micro
55 wait: false
56 security_group: "{{ vpc_sg_id }}"
57 network_interfaces:
58 - private_ip_address: "{{ ec2_ips[item] }}"
59 register: ec2_instances
60 loop:
61 - 0
62 - 1
63
64 # We only need these instances to be running
65 - name: Set variables for the instance IDs
66 ansible.builtin.set_fact:
67 instance_id_1: "{{ ec2_instances.results[0].instance_ids[0] }}"
68 instance_id_2: "{{ ec2_instances.results[1].instance_ids[0] }}"
69
70 # ============================================================
71 - name: Test attaching and detaching network interfaces
72 ansible.builtin.include_tasks: ./test_eni_basic_creation.yaml
73 - name: Test attaching and detaching network interfaces
74 ansible.builtin.include_tasks: ./test_ipaddress_assign.yaml
75 - name: Test attaching and detaching network interfaces
76 ansible.builtin.include_tasks: ./test_attachment.yaml
77 - name: Test attaching and detaching multiple network interfaces
78 ansible.builtin.include_tasks: ./test_create_attached_multiple.yml
79 - name: Test modifying source_dest_check
80 ansible.builtin.include_tasks: ./test_modifying_source_dest_check.yaml
81 - name: Test modifying tags
82 ansible.builtin.include_tasks: ./test_modifying_tags.yaml
83 - name: Test modifying delete_on_termination
84 ansible.builtin.include_tasks: ./test_modifying_delete_on_termination.yaml
85 - name: Test deleting ENIs
86 ansible.builtin.include_tasks: ./test_deletion.yaml
87 always:
88 # ============================================================
89 # Some test problems are caused by "eventual consistency"
90 # describe the ENIs in the account so we can see what's happening
91 - name: Describe ENIs in account
92 amazon.aws.ec2_eni_info: {}
93
94 # ============================================================
95 - name: Remove the network interfaces
96 amazon.aws.ec2_eni:
97 eni_id: "{{ item }}"
98 force_detach: true
99 state: absent
100 ignore_errors: true
101 retries: 5
102 loop:
103 - "{{ eni_id_1 | default(omit) }}"
104 - "{{ eni_id_2 | default(omit) }}"
105 - "{{ eni_id_3 | default(omit) }}"
106
107 - name: Terminate the instances
108 amazon.aws.ec2_instance:
109 state: absent
110 instance_ids:
111 - "{{ instance_id_1 }}"
112 - "{{ instance_id_2 }}"
113 wait: true
114 ignore_errors: true
115 retries: 5
116 when: instance_id_1 is defined and instance_id_2 is defined
117
118 - name: Remove the security group
119 amazon.aws.ec2_security_group:
120 name: "{{ resource_prefix }}-sg"
121 description: "{{ resource_prefix }}"
122 rules: []
123 state: absent
124 vpc_id: "{{ vpc_result.vpc.id }}"
125 ignore_errors: true
126 retries: 5
127
128 - name: Remove the subnet
129 amazon.aws.ec2_vpc_subnet:
130 cidr: "{{ vpc_cidr }}"
131 az: "{{ availability_zone }}"
132 vpc_id: "{{ vpc_result.vpc.id }}"
133 state: absent
134 ignore_errors: true
135 retries: 5
136 when: vpc_subnet_result is defined
137
138 - name: Remove the VPC
139 amazon.aws.ec2_vpc_net:
140 name: "{{ resource_prefix }}-vpc"
141 cidr_block: "{{ vpc_cidr }}"
142 state: absent
143 ignore_errors: true
144 retries: 5