Skip to content

Instantly share code, notes, and snippets.

@rei999
Last active December 19, 2015 20:49
Show Gist options
  • Select an option

  • Save rei999/6015928 to your computer and use it in GitHub Desktop.

Select an option

Save rei999/6015928 to your computer and use it in GitHub Desktop.
ansible - launch a ec2 instance
- name: create instances
hosts: localhost
vars:
keypair: myKeyPair
security_group: mySecurityGroup
instance_type: t1.micro
image: ami-05355a6c
count: 1
region: us-east-1
user: ec2-user
sudo: no
tasks:
- name: launch instances
local_action: ec2 keypair={{keypair}} group={{security_group}} instance_type={{instance_type}} image={{image}} wait=true count={{count}} region={{region}} instance_tags='{"Name":"ansible"}'
register: ec2
- name: add all instance public IPs to host group
local_action: add_host hostname={{item.public_ip}} groupname=ec2-servers ansible_ssh_user=ec2-user ansible_ssh_private_key_file=/etc/ansible/wundr_rest.pem
with_items: ec2.instances
- name: Create volumes and attach
local_action: ec2_vol instance={{item.id}} volume_size=8 region={{region}} device_name=xvdf
with_items: ec2.instances
register: ec2_vol
- name: wait for ssh to come up
local_action: wait_for host={{item.public_dns_name}} port=22 timeout=320 state=started
with_items: ec2.instances
- name: get instances stats
hosts: ec2-servers
sudo: true
gather_facts: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment