|
10 | 10 | # 2 aws_eip |
11 | 11 | # 1 ec2 instance |
12 | 12 |
|
| 13 | +- name: AMI Registration from EBS Snapshot |
| 14 | + amazon.aws.ec2_ami: |
| 15 | + name: "{{ aws_tag_creator }}-Controller" |
| 16 | + region: "{{ aws_region }}" |
| 17 | + state: present |
| 18 | + architecture: x86_64 |
| 19 | + virtualization_type: hvm |
| 20 | + root_device_name: /dev/xvda |
| 21 | + device_mapping: |
| 22 | + - device_name: /dev/xvda |
| 23 | + snapshot_id: "{{ volume_snapshots[0] }}" |
| 24 | + delete_on_termination: true |
| 25 | + volume_type: gp2 |
| 26 | + tags: |
| 27 | + Name: "{{ aws_tag_creator }}-Controller" |
| 28 | + Creator: "{{ aws_tag_creator }}" |
| 29 | + when: volume_snapshots |
| 30 | + register: ami_result |
| 31 | + |
13 | 32 |
|
14 | 33 | # NICs |
15 | 34 | - name: Filter required subnets for instance creation. Set aws_mgmt_subnet and aws_transport_subnet facts |
|
91 | 110 | count: 1 |
92 | 111 | instance_type: "{{ aws_vsmart_instance_type }}" |
93 | 112 | image: |
94 | | - id: "{{ aws_vsmart_ami_id }}" |
| 113 | + id: "{{ ami_result.image_id if volume_snapshots else aws_vmanage_ami_id }}" |
95 | 114 | state: present |
96 | 115 | vpc_subnet_id: "{{ aws_mgmt_subnet.id }}" |
97 | 116 | region: "{{ aws_region }}" |
|
117 | 136 | delete_on_termination: true |
118 | 137 | register: ec2_vsmart |
119 | 138 |
|
| 139 | +- name: Deregister/Delete AMI (keep associated snapshots) |
| 140 | + amazon.aws.ec2_ami: |
| 141 | + image_id: "{{ ami_result.image_id }}" |
| 142 | + delete_snapshot: false |
| 143 | + state: absent |
| 144 | + region: "{{ aws_region }}" |
| 145 | + when: volume_snapshots |
| 146 | + |
120 | 147 | # TODO: |
121 | 148 | # Note that the variable: ec2_vsmart.instances[0].network_interfaces is returning a list of interfaces |
122 | 149 | # but that list can be different than device_index (so mgmt and transport are mixed) |
|
166 | 193 | purge_rules: false |
167 | 194 | purge_tags: false |
168 | 195 | purge_rules_egress: false |
169 | | - rules: |
| 196 | + rules: "{{ sg_rules_vsmart }}" |
| 197 | + rules_egress: "{{ sg_rules_vsmart if aws_sg_block_egress else [] }}" |
| 198 | + register: allow_traffic |
| 199 | + retries: 3 |
| 200 | + delay: 3 |
| 201 | + until: allow_traffic is succeeded |
| 202 | + vars: |
| 203 | + sg_rules_vsmart: |
170 | 204 | - proto: all |
171 | 205 | cidr_ip: "{{ eip_vsmart.results[0].public_ip }}/32" |
172 | 206 | rule_desc: "{{ hostname }} - mgmt (VPN 512)" |
173 | 207 | - proto: all |
174 | 208 | cidr_ip: "{{ eip_vsmart.results[1].public_ip }}/32" |
175 | 209 | rule_desc: "{{ hostname }} - transport (VPN 0)" |
176 | | - rules_egress: [] |
177 | | - register: allow_traffic |
178 | | - retries: 3 |
179 | | - delay: 3 |
180 | | - until: allow_traffic is succeeded |
|
0 commit comments