Ansible: Orchestrate your Infrastructure

Jeremy Coates
Jeremy CoatesFounder & Chief Executive Officer (CEO) at Magma Digital Ltd
Orchestrate your Infrastructure
Magma Digital Ltd
Jeremy Coates
Who am I?๏ Jeremy Coates, MD at Magma Digital Ltd
๏ Founder of PHPNW
๏ Manchester Digital Association Council
๏ @phpcodemonkey
What is
use it?
๏ Only install on controller machine
๏ Requires: Python 2.6+, Paramiko (ssh), PyYAML, Jinja2
๏ RedHat: yum install ansible
๏ Debian: apt-get install ansible
๏ OS X: brew install ansible
๏ All: pip install ansible or from source
๏ Nothing much!
๏ SSH server
๏ Python 2.4+ and simplejson module
๏ Or just Python 2.6+
๏ Essentially any *nix distro in last decade
First 10 minutes
๏ Command line usage:
• ansible -i hosts -m ping all
• ansible webserver -m setup
• ansible -i /path/to/hosts -m <module>
[options e.g -vvvv] <host pattern>
• Default checks /etc/ansible/hosts
• -- check && -- diff
Inventory: Hosts
web ansible_ssh_host= ansible_ssh_port=2222 ansible_ssh_user=vagrant
web2 ansible_ssh_host= ansible_ssh_port=2201
db ansible_ssh_host= ansible_ssh_port=2202 ansible_ssh_user=vagrant
Inventory:Dynamic hosts
๏ Plugin scripts for:
• Amazon EC2
• Digital Ocean
• Linode
• Vagrant
• + others
๏ Or create your own CMDB (Configuration Management DB)
Playbooks๏ Commandline doesn’t scale: Playbooks do
๏ Playbooks are YAML
๏ ansible-playbook -i hosts playbook.yml
Sample Playbook
- hosts: localhost
user: root
motd_warning: 'WARNING: Use by ACME Employees ONLY'
- name: setup a MOTD
copy: dest=/etc/motd content={{ motd_warning }}
Playbooks๏ Language of playbooks relatively familiar to devs
๏ Targets - groups of tasks / vars etc.
๏ Vars - nice and obvious!
๏ Tasks - actions using modules / vars
๏ Includes - re-usable components
Playbooks Speed
๏ Playbooks default to 5 forks
• -- forks <N> to vary this
๏ async: <seconds> for long running processes
๏ poll: <seconds> check the progress
๏ Tags: target sections of play books
๏ Roles: convention to enable reuse of playbooks
Playbooks…๏ Looping: with_items:, with_fileglob:
๏ Conditional processing: when: ansible_os_family == ‘RedHat’
๏ Task Delegation: delegate_to: <host> or local_action:
๏ Vars: hostvars, groups, inventory*, environment
Playbook Templates
๏ Jinja2 template engine. Has access to any ansible facts
๏ Comments: {# a comment #}
๏ If/else: {% if 'authorativenames' in group_names %} {% else
%} {% endif %}
๏ Loops: {% for ip in ansible_all_ipv4_addresses %} {% end
for %}
Modules๏ Over 100 modules already exist
• Swiss army knife of machine management: ansible-doc
๏ Write own modules in any language, including PHP
๏ Module output key=value or JSON
๏ Runs on the machine to be configured
๏ Larger deployments (auto-scaling server farms etc.)
๏ Auto-update when repo changes
๏ Requires cron
Related?๏ ansible-vault - encryption for sensitive yaml files
๏ Ansible Guru - support subscription ($99/month)
๏ Ansible Tower (AWX) - commercial version
• Web console, REST API
• 50 machines from $2500/year (depending on support level
๏ Vagrant - Ansible provisioner module
Twitter: @ansible
IRC: #ansible (freenode)
Google Group: ansible-project
Ansible Weekly Newsletter:
Ansible Configuration Management:
(Daniel Hall: Packt Publishing Nov ’13 ISBN 978-1-78328-081-0)
๏ Jeremy Coates, MD at Magma Digital Ltd
๏ Founder of PHPNW
๏ Manchester Digital Association Council Member
๏ @phpcodemonkey
Simply Orchestrate
1 of 21

More Related Content

Viewers also liked(18)

El argentino n# 2625 01 3-121El argentino n# 2625 01 3-121
El argentino n# 2625 01 3-121
fede_bour696 views
Diagnóstico territorial de la exportación La RiojaDiagnóstico territorial de la exportación La Rioja
Diagnóstico territorial de la exportación La Rioja
EOI Escuela de Organización Industrial954 views
ConvegnoAsstra626 views
Feria Julio 2014 ValenciaFeria Julio 2014 Valencia
Feria Julio 2014 Valencia
Plaza De Toros Valencia366 views
Louise Foong329 views
Mira Centro ÓpticoMira Centro Óptico
Mira Centro Óptico
Miracentroptico89 views
Why is PHP AwesomeWhy is PHP Awesome
Why is PHP Awesome
Jeremy Coates7.5K views
Presentacio eportfoli IOCPresentacio eportfoli IOC
Presentacio eportfoli IOC
Joan Queralt2.4K views
LinuxCon 2015 Stateful NAT with OVSLinuxCon 2015 Stateful NAT with OVS
LinuxCon 2015 Stateful NAT with OVS
Thomas Graf4.1K views
2015 FOSDEM - OVS Stateful Services2015 FOSDEM - OVS Stateful Services
2015 FOSDEM - OVS Stateful Services
Thomas Graf5.2K views
Testing with CodeceptionTesting with Codeception
Testing with Codeception
Jeremy Coates20.6K views

More from Jeremy Coates(16)

Cyber Security and GDPRCyber Security and GDPR
Cyber Security and GDPR
Jeremy Coates3.9K views
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
Jeremy Coates887 views
Insects in your mindInsects in your mind
Insects in your mind
Jeremy Coates761 views
Jeremy Coates5.9K views
Hudson Continuous Integration for PHPHudson Continuous Integration for PHP
Hudson Continuous Integration for PHP
Jeremy Coates2.7K views
The Uncertainty PrincipleThe Uncertainty Principle
The Uncertainty Principle
Jeremy Coates2.3K views
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
Jeremy Coates32.6K views
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
Jeremy Coates9.6K views
Kiss Phpnw08Kiss Phpnw08
Kiss Phpnw08
Jeremy Coates2.3K views
Regex BasicsRegex Basics
Regex Basics
Jeremy Coates1.2K views
Search LuceneSearch Lucene
Search Lucene
Jeremy Coates2.2K views
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
Jeremy Coates63K views
Introduction to Version ControlIntroduction to Version Control
Introduction to Version Control
Jeremy Coates12.9K views
PHPNW Conference UpdatePHPNW Conference Update
PHPNW Conference Update
Jeremy Coates466 views

Recently uploaded(20)

Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum118 views
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya51 views

Ansible: Orchestrate your Infrastructure