Created
October 28, 2014 01:55
-
-
Save ober/da4e01f0bb08683b8c5b to your computer and use it in GitHub Desktop.
here
This file contains 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
# Use the ec2 module to create a new host and then add | |
# it to a special "ec2hosts" group. | |
- hosts: localhost | |
connection: local | |
gather_facts: False | |
tasks: | |
- name: Create Instance | |
ec2: image={{ item.value.image }} | |
instance_type={{ item.value.instance_type }} | |
keypair={{ item.value.keypair }} | |
instance_tags='{"Name":"{{ item.key }}", {{ item.value.tags }} }' | |
region={{ item.value.region }} | |
group={{ item.value.group }} | |
exact_count={{ item.value.exact_count }} | |
count_tag="{{item.value.count_tag}}" | |
wait=true | |
register: ec2_info | |
with_dict: instances | |
- debug: var=ec2_info | |
- debug: var=item | |
with_items: ec2_info.instance_ids | |
- add_host: hostname={{ item.public_ip }} groupname=ec2hosts | |
with_items: ec2_info.instances | |
- name: wait for instances to listen on port:22 | |
wait_for: | |
state=started | |
host={{ item.public_dns_name }} | |
port=22 | |
with_items: ec2_info.instances | |
- hosts: ec2hosts | |
gather_facts: True | |
user: ubuntu | |
sudo: True | |
tasks: | |
# fetch instance data from the metadata servers in ec2 | |
- ec2_facts: | |
# show all known facts for this host | |
- debug: var=hostvars[inventory_hostname] | |
# just show the instance-id | |
- debug: msg="{{ hostvars[inventory_hostname]['ansible_ec2_instance_id'] }}" | |
roles: | |
- common | |
- users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment