Jeff Geerling, author of Ansible for DevOps, demonstrates basic Ansible usage on the Dramble, a cluster of six Raspberry Pi 2 computers.
This presentation was delivered on July 8, 2015, at the Ansible St. Louis meetup, at Riot Games in Clayton, MO.
2. Who am I?
⢠Jeff Geerling (geerlingguy)
⢠Technical Architect, Acquia
⢠Owner, Midwestern Mac LLC
⢠Dev (mainly), Ops
3. Ansible for DevOps
⢠On LeanPub
⢠Nearly complete!
⢠50% off: http://bit.ly/ansible-stl
4. My Story
⢠First 'real' server build: a 486 PC, RedHat Linux 6
Gateway 2000 4DX2-66v
RedHat Linux 6.x
5. Today
Midwestern Mac Server Check.in Hosted Apache Solr
Personal
= 50+ prod servers,â¨
one very part-time sysadmin
6. ⢠âConďŹguration management for humans.â
⢠Uses SSH
⢠Secure, fast, simple
⢠300+ built-in modules
⢠Don't need conďŹguration management to manage
your conďŹguration management.
7. ⢠âConďŹguration management for humans.â
⢠Uses SSH
⢠Secure, fast, simple
⢠300+ built-in modules
⢠Don't need conďŹguration management to manage
your conďŹguration management.
 ___________
Â
Â
<
 And
 cows!
 >
Â
 -Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 ^__^
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 (oo)_______
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 (__)
Â
Â
Â
Â
Â
Â
 )/
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 ||-Ââ-Ââ-Ââ-Ââw
 |
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 ||
Â
Â
Â
Â
 ||
13. ⢠Check connectivity (always a good ďŹrst step!)â¨
$ ansible all -m ping
⢠Have fun with RGB LEDs!â¨
$ ansible webservers -a "rgb red" -s
Ad-Hoc Commands
14. ⢠Check connectivity (always a good ďŹrst step!)â¨
$ ansible all -m ping
⢠Have fun with RGB LEDs!â¨
$ ansible webservers -a "rgb red" -s
Ad-Hoc Commands
 ________
Â
<
 Shiny!
 >
Â
 -Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 ^__^
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 (oo)_______
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 (__)
Â
Â
Â
Â
Â
Â
 )/
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 ||-Ââ-Ââ-Ââ-Ââw
 |
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 ||
Â
Â
Â
Â
 ||
15. Demo
# Test connectivity.
ansible all -m ping
# Raspberry Pi RGB LEDs.
ansible all -a "rgb green" -s
ansible all -a "rgb blue" -s --forks=1
ansible all -a "rgb green" -s --forks=2
ansible all -a "colors 255 255 255" -s
# More useful commands.
ansible all -m setup
ansible all -a "free -m"
ansible all -m shell -a "ifconfig | grep inet" -s
ansible all -m user -a "name=pgibbons state=absent remove=yes" -s
ansible webservers -m service -a "name=nginx state=restarted" -s --forks=2
Download playbook examples
16. Playbooks
⢠Ad-Hoc commands don't solve the snowďŹake
problem
⢠"infrastructure as code"
⢠Simple YAML ďŹles
⢠Run with: ansible-playbook
Unique, by Pen Waggener
17. Playbooks
#!/bin/bash
# Shell script to install/configure Apache.
# Install Apache.
yum install --quiet -y httpd httpd-devel
# Copy configuration files.
cp /path/to/config/httpd.conf
/etc/httpd/conf/httpd.conf
cp /path/to/config/httpd-vhosts.conf
/etc/httpd/conf/httpd-vhosts.conf
# Start Apache.
service httpd start
# Set Apache to run on startup.
chkconfig httpd on
18. Playbooks
#!/bin/bash
# Shell script to install/configure Apache.
# Install Apache.
yum install --quiet -y httpd httpd-devel
# Copy configuration files.
cp /path/to/config/httpd.conf
/etc/httpd/conf/httpd.conf
cp /path/to/config/httpd-vhosts.conf
/etc/httpd/conf/httpd-vhosts.conf
# Start Apache.
service httpd start
# Set Apache to run on startup.
chkconfig httpd on
---
# Playbook to install/configure Apache.
hosts: all
tasks:
- name: Install Apache.
yum: name={{ item }} state=present
with_items:
- httpd
- httpd-devel
- name: Copy configuration files.
copy: "src={{ item.src }} dest={{ item.dest }}"
with_items:
- { src: "/path/to/config/httpd.conf",
dest: "/etc/httpd/conf/httpd.conf" }
- { src: "/path/to/config/httpd-vhosts.conf",
dest: "/etc/httpd/conf/httpd-vhosts.conf" }
- name: Ensure Apache is started and runs on startup.
service: name=httpd state=started enabled=yes
19. Demo
# Run just the users playbook.
ansible-playbook users.ml
# Run the users playbook again, to demonstrate idempotence.
ansible-playbook users.yml
# Run the web playbook (twice, again).
ansible-playbook web.yml
ansible-playbook web.yml
# Run the main playbook that includes users.yml and web.yml
ansible-playbook main.yml
ansible-playbook main.yml
Download playbook examples
20. Roles
⢠Like: Libraries, packages, conďŹg bundles
⢠Encapsulate conďŹguration in smaller, reusable
chunks
⢠4,000+ contributed roles on Ansible Galaxy
⢠To create: ansible-galaxy init [role-name]
21. Demo
Role folder structure:
rolename/
defaults/
main.yml <-- Most variables go here, so you can override if needed.
handlers/
main.yml
meta/
main.yml
tasks/
main.yml
tests/ <-- See Testing Ansible Roles with Travis CI on GitHub
vars/
main.yml <-- Special and static variables go here.
Download playbook examples
22. More Ansible
⢠Ansible Tower, Jenkins integration, CI
⢠Docker integration
⢠AWS, DigitalOcean, Rackspace, Softlayer, Linode, etc.
⢠NotiďŹcations
⢠Rolling updates
⢠Ansible Vault
⢠etc...
23. More Ansible
⢠Ansible Tower, Jenkins integration, CI
⢠Docker integration
⢠AWS, DigitalOcean, Rackspace, Softlayer, Linode, etc.
⢠NotiďŹcations
⢠Rolling updates
⢠Ansible Vault
⢠etc...
 ______________________________
Â
<
 Follow
 @AnsiBull
 on
 Twitter!
 >
Â
 -Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ-Ââ
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 ^__^
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 (oo)_______
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 (__)
Â
Â
Â
Â
Â
Â
 )/
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 ||-Ââ-Ââ-Ââ-Ââw
 |
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
 ||
Â
Â
Â
Â
 ||
24. More Resources
⢠Ansible documentation
⢠Ansible Vagrant examples
⢠Ansible for DevOps
⢠50% off: http://bit.ly/ansible-stl
⢠Raspberry Pi Dramble
⢠Example playbook from this presentation