Created
May 23, 2014 08:51
-
-
Save craigmarvelley/9a27c53413c5010b9ad4 to your computer and use it in GitHub Desktop.
Launch and provision EC2 instances in one go
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
--- | |
- name: Launch new instances | |
local_action: | |
module: ec2 | |
aws_access_key: "{{ aws_access_key }}" | |
aws_secret_key: "{{ aws_secret_key }}" | |
region: "{{ ec2_region }}" | |
keypair: "{{ ec2_keypair }}" | |
group: "{{ ec2_group }}" | |
instance_type: "{{ ec2_instance_type }}" | |
image: "{{ ec2_image }}" | |
count: "{{ ec2_count }}" | |
wait: yes | |
register: launched_instances | |
- name: Add all instance public IPs to a host group so they can be referenced in tasks | |
add_host: hostname={{ item.public_ip }} groupname=launched_instance_hosts | |
with_items: launched_instances.instances | |
- name: Wait until SSH is available | |
local_action: wait_for host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started | |
with_items: launched_instances.instances |
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
--- | |
- name: Launch and configure ec2 instances | |
hosts: | |
- 127.0.0.1 | |
connection: local | |
gather_facts: false | |
vars_files: | |
- vars/credentials.yml | |
roles: | |
- { role: launch_instances } | |
- { role: tag_instances } | |
- name: Configure ec2 instances post-creation | |
hosts: launched_instance_hosts # uses a var defined dynamically in the previous playbook | |
user: ubuntu | |
sudo: yes | |
gather_facts: true | |
roles: | |
- { role: webserver } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment