Getting Started in AWS and Eucalyptus - AnsibleFest 2013

17

description

Presentation from 2013 AnsibleFest which describes practices for using Ansible against AWS and Eucalyptus clouds.

Transcript of Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Page 1: Getting Started in AWS and Eucalyptus - AnsibleFest 2013
Page 2: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Getting Started in AWS & Eucalyptus

Lester Wade@LesterWade

Page 3: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Why Ansible?

New and interesting.Subsequently found to be awesome.Contribution is easy.Python (note to python-boto).

Page 4: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

AWS Modules

ec2ec2_factsec2_volec2_elbrdscloudformations3

Page 5: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Two aspects...

1. Working with AWS (compatible) services.

2. Working with the resources (instances).

Page 6: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Example:

ec2 provision + load balance + configure

Page 7: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Provision + Load Balance: tasks:

- name: Launch instance

local_action: ec2 keypair=mykey group=mygroup instance_type=m1.small image=emi- wait=true region=eu-west-1

register: ec2

- name: Add new instance to host group

local_action: add_host hostname=${item.public_ip} groupname=launched

with_items: ${ec2.instances}

- name: Wait for SSH to come up

local_action: wait_for host=${item.public_dns_name} port=22 delay=60 timeout=320 state=started

with_items: ${ec2.instances}

- name: Add the instance to my LB

local_action: ec2_elb instance_id=${item.id} state=present ec2_elbs=lwadeelb

with_items: ${ec2.instances}

Page 8: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Configure (based on dynamic host group) - name: Configure instance(s)

hosts: launched

gather_facts: True

handlers:

- name: restart apache

action: service name=httpd state=restarted

tasks:

- name: Ensure NTP is up and running

action: service name=ntpd state=started

- name: Install Apache

action: yum name=httpd state=latest

notify: restart apache

- name: Copy index.html

action: copy src=files/index.html dest=/var/www/html/index.html owner=root group=root

notify: restart apache

Page 9: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

"Oh nice, I can automate instance launch and configuration but what now... ?"

Page 10: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Working with instances (2)

Transient

- auto-scale in/out- die

Page 11: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Example: inventory plugin

Example: ansible-pull

Page 12: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Schedule continual snapshot in cron(tab):# Refresh EC2 inventory cache every 15 minutes

MAILTO="root@localhost"

*/15 * * * * /etc/ansible/ec2.py --refresh-cache

# Consider refresh-cache prior to crontab'ed playbook execution

Utilize inventory:ansible-playbook -i /etc/ansible/ec2.py tag_Name_ansiblefest -m ping --private-key=/my/pri.key

Page 13: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Bake ansible + ansible-pull into an image. Run on boot or cron. rc.local or crontab -l:

# Ansible first-boot run

ansible-pull -d /var/lib/ansible/local -U https://github.com/lwade/ansiblefest.git >> /var/log/ansible-pull.log 2>&1

Page 14: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Working with instances (2)

Transient (e.g. auto-scaled in/out)Image-backed*

Page 15: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

* Raw vs. Baked Images

choco chip cookie, Bob Smith

Page 17: Getting Started in AWS and Eucalyptus - AnsibleFest 2013

Thanks