Modern Infrastructure
as Code with Ansible
Joe Ferguson
Who Am I?
Joe Ferguson
Senior Full Stack Dev @ Preteckt
Open Source Geek
⚽,🏒, and 🏎 fan
Twitter: @JoePFerguson
Ansible for DevOps
https://leanpub.com/ansible-for-devops
pip install ansible
Ansible Concepts 🤔
Modules
Standalone work units to perform a task
Inventory Configuration
Declaration of target systems to perform tasks upon
Playbooks
Complete set of roles / list of actions to take
Command Module
Command Module
Command Module
Create Ansible Playbook
Create Ansible Playbook
Create Ansible Playbook
Running Our Ansible
Playbook
Ansible Variable Precedence
http://docs.ansible.com/ansible/playbooks_variables.html
Ansible Variable Precedence
• command line values (eg “-u user”)
• role defaults
• inventory file or script group vars
Reusing Playbooks from
others
Ansible Galaxy Authors
Adding geerlingguy.php
Overriding Variables
Overriding Variables
Adding ansible-role-php
Adding ansible-role-php
Running ansible-role-php
Production Inventory
Staging Inventory
Dev Inventory
ansible_playbook -i prod.ini <playbook>
ansible_playbook -i staging.ini <playbook>
ansible_playbook -i dev.ini <playbook>
Ansible can deploy
your code
General Ansible Advice
Use environment based playbooks & inventory files
for clear separation & to easily handle one off
differences
Use Python or some other environment variable
system for managing your secrets!
Couple variables to the most focused point, then raise
their scope as you need
Ansible Tower
https://www.ansible.com/products/tower
Ansible Tower
https://www.ansible.com/products/tower/pricing
AWX - Open Source Tower
AWX - Open Source Tower
Virtual Environments
Install Dependencies
Install Dependencies
Freeze Dependencies
Building a Deploy Playbook
http://vcdt.joeferguson.me/
Playbook File
deploy-vcdt-app Role
deploy-vcdt-app Role
Using Jinja2 Templates
Update the Repository
Composer Install
Application Setup
Job’s Done!
Break Up Large
YAML
System Maintenance
System Maintenance
Install & Configure Certbot
Create SSL & Cron
Combine SSL For HAProxy
Delayed Service Restarting
Renewal Post Hook Script
Renewal Post Hook Script
Install Docker
Install Docker
Add Users
Looping over Arrays (Hashes)
Keep Your Secrets
Secret!
Rolling Updates: Serial
Maximum Failure
Directory Layout
Directory Layout
Directory Layout
Joe Ferguson
Twitter: @JoePFerguson
Email: joe@joeferguson.me
Contact Info:
Thanks!

Modern infrastructure as code with ansible PyTN