2. @pas256 @Answers4AWS
• Engineer
• Founder of Answers for AWS
• Wrote the EC2 inventory plugin for Ansible
• Run the Advanced AWS meetup in SF
• Won a NetflixOSS Cloud Prize for my Ansible
playbooks
About Me
5. @pas256 @Answers4AWS
• Easy to read, write and share playbooks
• Thousands of modules *
• Great documentation
• Support
Why is it easy?
* 2015 projection
8. @pas256 @Answers4AWS
!
!
!
- name: Install Apache web server
apt: pkg=apache2 state=latest
What does this do?
Documentation
Arguments
Module
9. @pas256 @Answers4AWS
- name: Install Apache web server with PHP
apt: pkg={{ item }} state=latest
with_items:
- apache2
- php5
- libapache2-mod-php5
- php-apc
!
10. @pas256 @Answers4AWS
- name: Install Apache web server with PHP (apt version)
apt: pkg={{ item }} state=latest
with_items:
- apache2
- php5
- libapache2-mod-php5
- php-apc
when: ansible_distribution == ‘Ubuntu'"
!
!
- name: Install Apache web server with PHP (yum version)
yum: pkg={{ item }} state=latest
with_items:
- httpd24
- php55
- php55-pecl-apc
when: ansible_distribution == 'Amazon'
11. @pas256 @Answers4AWS
- name: Copy website configuration
copy: src=site.conf
dest=/etc/apache2/sites-available/site.conf
owner=root
group=root
mode=0755
notify: restart apache
tags: config
A little more complex
12. @pas256 @Answers4AWS
• Contains one or more “plays”
• Written in YAML
• Declare configuration
• YAML is not code
• Executed in the order it is
written
• No dependency graph
Playbooks
13. @pas256 @Answers4AWS
• apt/yum/pip
• Add/Remove packages
• command/shell
• Execute any shell command
(with or without environment)
• copy
• Copy a file from source to
destination on host
• file
• Create directories, symlinks,
change permissions
• service
• Start/Stop/Enable services
• template
• Same as copy, but with
variable substitutions in file
Modules
16. @pas256 @Answers4AWS
• Reuse a set of tasks, files, variables and templates
• Ansible Galaxy for being social
• Web
• Database
• System
• more…
Roles
22. @pas256 @Answers4AWS
• Use CloudFormation
• Dependency management
• Delete for free
• Ultimate combination
• python + boto + troposphere
Don’t do this on AWS
25. @pas256 @Answers4AWS
• Run in local mode
• Do not start services
• Use Ansible provisioner for
• aminator
• packer
• Use Bakery4AWS (apply for beta access)
Image creation
28. @pas256 @Answers4AWS
Same playbook can:
• Run on a single instance
• Run on multiple instances
Flexible playbooks
Ansible
Playbook
Laptop
29. @pas256 @Answers4AWS
Same playbook can:
• Run on a single instance
• Run on multiple instances
• Run against multiple OSes
Flexible playbooks
Ansible
Playbook
Laptop
30. @pas256 @Answers4AWS
Same playbook can:
• Run on a single instance
• Run on multiple instances
• Run against multiple OSes
• Run in local mode to
create image
Flexible playbooks
Ansible
Playbook
Laptop
Packer/Aminator
31. @pas256 @Answers4AWS
Four things to consider to write highly flexible
playbooks
• Header
• Common variables
• Services
• Handlers
How?
34. @pas256 @Answers4AWS
- name: Enable Apache HTTP Web Server service
service: name=httpd enabled=yes"
!
- name: Starting Apache HTTP Web Server service
service: name=httpd state=started
when: not_ami_build"
!
- name: Stopping Apache HTTP Web Server service
service: name=httpd state=stopped
when: ami_build
Services