-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-host.yml
37 lines (34 loc) · 992 Bytes
/
create-host.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
---
- name: add host to AWS
hosts: all
collections:
- amazon.aws
tasks:
# - name: set fact true
# set_fact:
# public_ip: true
# when: ( assign_public_ip == "true" )
# - name: set fact false
# set_fact:
# public_ip: false
# when: ( assign_public_ip == "false" )
- name: add host
ec2_instance:
name: "{{ instance_name }}-{{ host_number }}"
key_name: "{{ ssh_key_name }}"
vpc_subnet_id: "{{ vpc_subnet_id }}"
instance_type: "{{ ec2_instance_type }}"
security_group: "{{ security_group }}"
network:
assign_public_ip: "{{ assign_public_ip | bool }}"
image_id: "{{ image_id }}"
access_key: "{{ access_key }}"
secret_key: "{{ secret_key }}"
state: present
region: "{{ aws_region }}"
register: host_info
when: inventory_hostname == play_hosts[0]
- name: print hosts
debug:
var: host_info.instances[0].public_ip_address
when: inventory_hostname == play_hosts[0]