Skip to content

Instantly share code, notes, and snippets.

@chadoh
Created June 7, 2013 16:09
Show Gist options
  • Select an option

  • Save chadoh/5730413 to your computer and use it in GitHub Desktop.

Select an option

Save chadoh/5730413 to your computer and use it in GitHub Desktop.
---
# This playbook is an example for deploying multiple instances into EC2/Euca and "doing something" with them.
# - uses the ec2 and ec2_vol module.
#
# 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:
# ansible-playbook eucalyptus-ec2-deploy.yml -v --private-key=/path/to/ec2/pri/key
- name: Set up a new ubuntu instance and register it in your ansible inventory file
hosts: local
connection: local
user: root
gather_facts: false
vars:
keypair: pd-app-server
instance_type: c1.medium
security_group: default
image: ami-d0f89fb9 # default ubuntu, provided by the aws wizard
tasks:
# Launch 1 instances with the following parameters. Register the output.
- name: Launch instance
local_action: ec2 key_name={{keypair}} group={{security_group}}
instance_type={{instance_type}} image={{image}}
instance_tags='{"Name":{{instance_name}}, "role":"dev"}'
wait=true count=1
register: ec2
# Use with_items to add each instance's public IP to a new hostgroup for use in the next play.
- name: Add new instances to host group
local_action: add_host hostname={{item.public_ip}} groupname=dev
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
#local_action: ec2_vol volume_size=10 instance={{item.id}}
#ec2_access_key={{access_key}} ec2_secret_key={{secret_key}}
#with_items: ${ec2.instances}
@chadoh
Copy link
Copy Markdown
Author

chadoh commented Jun 7, 2013

running this with ansible-playbook ansible/playbooks/launch_ubuntu_instance.yml -v --private-key=/Users/chadoh/.ssh/pd-app-server --extra-vars="instance_name=chad-testing-ansible" gives this error:

 _______________________
< TASK: Launch instance >
 -----------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


failed: [localhost] => {"failed": true, "parsed": false}
invalid output was: Traceback (most recent call last):
  File "/Users/chadoh/.ansible/tmp/ansible-1370621513.78-255736190875368/ec2", line 1300, in <module>
    main()
  File "/Users/chadoh/.ansible/tmp/ansible-1370621513.78-255736190875368/ec2", line 354, in main
    ec2.create_tags(instids, module.from_json(instance_tags))
  File "/Users/chadoh/.ansible/tmp/ansible-1370621513.78-255736190875368/ec2", line 1136, in from_json
    return json.loads(data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded


FATAL: all hosts have already failed -- aborting

@chadoh
Copy link
Copy Markdown
Author

chadoh commented Jun 7, 2013

/etc/ansible/hosts looks like this:

[local]
localhost ansible_connection=local

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment