2013-05-05 20:02:39 +02:00
|
|
|
---
|
2013-12-12 20:30:42 +01:00
|
|
|
# This playbook is an example for deploying multiple instances into
|
|
|
|
# EC2/Euca and "doing something" with them.
|
|
|
|
#
|
|
|
|
# - uses the ec2 and ec2_vol module.
|
2013-05-05 20:02:39 +02:00
|
|
|
#
|
2013-12-12 20:30:42 +01:00
|
|
|
# Run this with ansible-playbook and supply the private key for your
|
|
|
|
# EC2/Euca user (to access the instance in the second play), e.g:
|
|
|
|
#
|
2013-05-05 20:02:39 +02:00
|
|
|
# ansible-playbook eucalyptus-ec2-deploy.yml -v --private-key=/path/to/ec2/pri/key
|
2013-12-12 20:30:42 +01:00
|
|
|
#
|
2013-05-05 20:02:39 +02:00
|
|
|
|
2013-12-12 20:30:42 +01:00
|
|
|
# The play operates on the local (Ansible control) machine.
|
2013-05-05 20:02:39 +02:00
|
|
|
- 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
|
2013-12-12 20:30:42 +01:00
|
|
|
ec2: keypair={{keypair}} group={{security_group}}
|
|
|
|
instance_type={{instance_type}} image={{image}}
|
|
|
|
wait=true count=5
|
2013-05-05 20:02:39 +02:00
|
|
|
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
|
2013-12-12 20:30:42 +01:00
|
|
|
add_host: hostname={{item.public_ip}} groupname=deploy
|
2013-12-07 19:25:19 +01:00
|
|
|
with_items: ec2.instances
|
2013-05-05 20:02:39 +02:00
|
|
|
|
2013-06-14 18:11:07 +02:00
|
|
|
- name: Wait for the instances to boot by checking the ssh port
|
2013-12-12 20:30:42 +01:00
|
|
|
wait_for: host={{item.public_dns_name}} port=22 delay=60 timeout=320 state=started
|
2013-12-07 19:25:19 +01:00
|
|
|
with_items: ec2.instances
|
2013-06-14 18:11:07 +02:00
|
|
|
|
2013-12-12 20:30:42 +01:00
|
|
|
# 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.
|
2013-05-05 20:02:39 +02:00
|
|
|
|
|
|
|
- name: Create a volume and attach
|
2013-12-12 20:30:42 +01:00
|
|
|
ec2_vol: volume_size=20 instance={{item.id}}
|
2013-12-07 19:25:19 +01:00
|
|
|
with_items: ec2.instances
|
2013-05-05 20:02:39 +02:00
|
|
|
|
|
|
|
|
2013-12-12 20:30:42 +01:00
|
|
|
# This play targets the new host group
|
2013-05-05 20:02:39 +02:00
|
|
|
- name: Configure instance
|
|
|
|
hosts: deploy
|
|
|
|
user: root
|
|
|
|
|
|
|
|
# Do some stuff on each instance ....
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: Ensure NTP is up and running
|
2013-12-12 20:30:42 +01:00
|
|
|
service: name=ntpd state=started
|
2013-05-05 20:02:39 +02:00
|
|
|
|
|
|
|
- name: Install Apache Web Server
|
2013-12-12 20:30:42 +01:00
|
|
|
yum: pkg=httpd state=latest
|