mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adding ec2-related module example to examples/playbooks
This commit is contained in:
parent
3b9cf8270f
commit
2dbe01ea7c
1 changed files with 53 additions and 0 deletions
53
examples/playbooks/eucalyptus-ec2.yml
Normal file
53
examples/playbooks/eucalyptus-ec2.yml
Normal file
|
@ -0,0 +1,53 @@
|
|||
---
|
||||
# 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: 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
|
||||
local_action: 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
|
||||
local_action: add_host hostname=${item.public_ip} groupname=deploy
|
||||
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=20 instance=${item.id}
|
||||
with_items: ${ec2.instances}
|
||||
|
||||
# This play targets the new host group
|
||||
|
||||
- name: Configure instance
|
||||
hosts: deploy
|
||||
user: root
|
||||
gather_facts: True
|
||||
|
||||
# Do some stuff on each instance ....
|
||||
|
||||
tasks:
|
||||
- name: Ensure NTP is up and running
|
||||
action: service name=ntpd state=started
|
||||
|
||||
- name: Install Apache Web Server
|
||||
action: yum pkg=httpd state=latest
|
Loading…
Reference in a new issue