Created
February 7, 2018 10:39
-
-
Save foxutech/37b79ee3184aa9d08ed657053382583e to your computer and use it in GitHub Desktop.
rolemain.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Provision EC2 Box | |
local_action: | |
module: ec2 | |
key_name: "{{ ec2_keypair }}" | |
group_id: "{{ ec2_security_group }}" | |
instance_type: "{{ ec2_instance_type }}" | |
image: "{{ ec2_image }}" | |
vpc_subnet_id: "{{ ec2_subnet_ids|random }}" | |
region: "{{ ec2_region }}" | |
instance_tags: '{"Name":"{{ec2_tag_Name}}","Type":"{{ec2_tag_Type}}","Environment":"{{ec2_tag_Environment}}"}' | |
assign_public_ip: yes | |
wait: true | |
count: 1 | |
volumes: | |
- device_name: /dev/sda1 | |
device_type: gp2 | |
volume_size: "{{ ec2_volume_size }}" | |
delete_on_termination: true | |
register: ec2 | |
- debug: var=item | |
with_items: ec2.instances | |
- add_host: name={{ item.public_ip }} > | |
groups=tag_Type_{{ec2_tag_Type}},tag_Environment_{{ec2_tag_Environment}} | |
ec2_region={{ec2_region}} | |
ec2_tag_Name={{ec2_tag_Name}} | |
ec2_tag_Type={{ec2_tag_Type}} | |
ec2_tag_Environment={{ec2_tag_Environment}} | |
ec2_ip_address={{item.public_ip}} | |
with_items: ec2.instances | |
- name: Wait for the instances to boot by checking the ssh port | |
wait_for: host={{item.public_ip}} port=22 delay=60 timeout=320 state=started | |
with_items: ec2.instances |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment