Skip to content

Instantly share code, notes, and snippets.

@tgerla
Created September 17, 2014 18:01
Show Gist options
  • Save tgerla/0e71ea20bcdf37013179 to your computer and use it in GitHub Desktop.
Save tgerla/0e71ea20bcdf37013179 to your computer and use it in GitHub Desktop.
- name: Stage instance(s)
hosts: local
connection: local
user: root
gather_facts: false
vars:
keypair: mykeypair
instance_type: m1.small
security_group: default
image: emi-048B3A37
# Launch 5 instances with the following parameters. Register the output.
tasks:
- name: Launch instance
ec2: keypair={{keypair}} group={{security_group}}
instance_type={{instance_type}} image={{image}}
wait=true count=5
register: ec2
# Use with_items to add each instances public IP to a new hostgroup for use in the next play.
- name: Add new instances to host group
add_host: hostname={{item.public_ip}} groupname=deploy
with_items: ec2.instances
- name: Wait for the instances to boot by checking the ssh port
wait_for: host={{item.public_dns_name}} port=22 delay=60 timeout=320 state=started
with_items: ec2.instances
# Use the ec2_vol module to create volumes for attachment to each instance.
# Use with_items to attach to each instance (by returned id) launched previously.
- name: Create a volume and attach
ec2_vol: volume_size=20 instance={{item.id}}
with_items: ec2.instances
# This play targets the new host group, using ubuntu authentication
- name: bootstrap authentication
hosts: ubuntu
remote_user: ubuntu
sudo: yes
roles:
- common_role
# this play uses "deploy" user created by the common_role play
- name: bootstrap authentication
hosts: ubuntu
user: deploy
tasks:
- name: Ensure NTP is up and running
service: name=ntpd state=started
- name: Install Apache Web Server
yum: pkg=httpd state=latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment