-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsolution_provision_ec2_instance.yml
84 lines (74 loc) · 3.67 KB
/
solution_provision_ec2_instance.yml
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
- name: EC2 Cloud Operations
hosts: localhost
connection: local
gather_facts: false
module_defaults:
group/aws:
region: us-east-1
vars:
my_instance:
name: instance-lightspeed-01
key_name: lightspeed-keypair
image_id: ami-016eb5d644c333ccb # RHEL 9 us-east-1
network:
assign_public_ip: true
tags:
function: demo-lightspeed
security_group: secgroup-lightspeed
wait: true
tasks:
############################################## INSTRUCTIONS TASK 1 and 2 ##############################################
# Press "ENTER" at the end of the multi-task prompt line just after this instructions block. DO NOT UNCOMMENT THE LINE.
# Press "TAB" to accept suggestion.
# Note - The suggestion used the Fully Qualified Collection Name (FQCN).
# Note - The first task used the correct AWS tag "tag:Name" in the filter.
# Note - The second task used the correct variable created in the previous task.
#######################################################################################################################
# Get subnet-lightspeed info & create vpc_subnet_id var
# Content suggestion provided by Ansible Lightspeed
- name: Get subnet-lightspeed info
register: subnet_info
amazon.aws.ec2_vpc_subnet_info:
filters:
tag:Name: subnet-lightspeed
- name: Create vpc_subnet_id var
ansible.builtin.set_fact:
vpc_subnet_id: "{{ subnet_info.subnets[0].id }}"
################################################# INSTRUCTIONS TASK 3 #################################################
# Uncomment the line just after this instructions block and Press "ENTER" at the end.
# Press "TAB" to accept suggestion.
# Note - The suggestion used the "my_instance" variable declared in the "vars:" section.
#######################################################################################################################
- name: Create t3.small instance using my_instance var
# Content suggestion provided by Ansible Lightspeed
amazon.aws.ec2_instance:
name: "{{ my_instance.name }}"
key_name: "{{ my_instance.key_name }}"
image_id: "{{ my_instance.image_id }}"
vpc_subnet_id: "{{ vpc_subnet_id }}"
instance_type: t3.small
network: "{{ my_instance.network }}"
wait: "{{ my_instance.wait }}"
tags: "{{ my_instance.tags }}"
security_group: "{{ my_instance.security_group }}"
register: ec2_instance
############################################## INSTRUCTIONS TASK 4 and 5 ##############################################
# Press "ENTER" at the end of the multi-task prompt line just after this instructions block. DO NOT UNCOMMENT THE LINE.
# Press "TAB" to accept suggestion.
# Note - The suggestion used the correct variable from the previous task.
# Note - The second task used the "public_ip_address" variable based on the previous task.
# First task note - The suggestion used the correct variable from the previous task and integrated "retries".
# Second task note - The suggestion used the "public_ip_address" variable based on the previous task.
#######################################################################################################################
# Create var from public_ip_address with retry & print it out
# Content suggestion provided by Ansible Lightspeed
- name: Create var from public_ip_address with retry
ansible.builtin.set_fact:
public_ip_address: "{{ ec2_instance.instances[0].public_ip_address }}"
retries: 10
delay: 10
until: public_ip_address is defined
- name: Print it out
ansible.builtin.debug:
msg: "{{ public_ip_address }}"