Ansible: Orchestrate your Infrastructure

Jeremy Coates
Jeremy CoatesFounder & Chief Executive Officer (CEO) at Magma Digital Ltd
@magma_digital
Orchestrate your Infrastructure
Magma Digital Ltd
Jeremy Coates
@magma_digital
Who am I?๏ Jeremy Coates, MD at Magma Digital Ltd
๏ Founder of PHPNW
๏ Manchester Digital Association Council
Member
๏ @phpcodemonkey
๏ linkedin.com/in/jeremycoates
@magma_digital
What is
Ansible?
SALT CHEFPUPPET Ansible
@magma_digital
Why
use it?
@magma_digital
Install:Controller
๏ 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
@magma_digital
Install:Remotes
๏ Nothing much!
๏ SSH server
๏ Python 2.4+ and simplejson module
๏ Or just Python 2.6+
๏ Essentially any *nix distro in last decade
@magma_digital
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
@magma_digital
Inventory: Hosts
[webservers]
web ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
web2 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2201
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
[dbservers]
db ansible_ssh_host=127.0.0.1 ansible_ssh_port=2202 ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
@magma_digital
Inventory:Dynamic hosts
๏ Plugin scripts for:
• Amazon EC2
• Digital Ocean
• Linode
• Vagrant
• + others
๏ Or create your own CMDB (Configuration Management DB)
@magma_digital
Playbooks๏ Commandline doesn’t scale: Playbooks do
๏ Playbooks are YAML
๏ ansible-playbook -i hosts playbook.yml
@magma_digital
Sample Playbook
---
- hosts: localhost
user: root
vars:
motd_warning: 'WARNING: Use by ACME Employees ONLY'
tasks:
- name: setup a MOTD
copy: dest=/etc/motd content={{ motd_warning }}
@magma_digital
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
@magma_digital
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
@magma_digital
Playbooks…๏ Looping: with_items:, with_fileglob:
๏ Conditional processing: when: ansible_os_family == ‘RedHat’
๏ Task Delegation: delegate_to: <host> or local_action:
shorthand
๏ Vars: hostvars, groups, inventory*, environment
@magma_digital
Playbook Templates
๏ Jinja2 template engine. Has access to any ansible facts
(vars)
๏ Comments: {# a comment #}
๏ If/else: {% if 'authorativenames' in group_names %} {% else
%} {% endif %}
๏ Loops: {% for ip in ansible_all_ipv4_addresses %} {% end
for %}
@magma_digital
Modules๏ Over 100 modules already exist
• Swiss army knife of machine management: ansible-doc
๏ Write own modules in any language, including PHP
(json_encode)
๏ Module output key=value or JSON
@magma_digital
Ansible-pull
๏ Runs on the machine to be configured
๏ Larger deployments (auto-scaling server farms etc.)
๏ Auto-update when repo changes
๏ Requires cron
@magma_digital
SHARE REUSEENHANCE
@magma_digital
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
needed)
๏ Vagrant - Ansible provisioner module
@magma_digital
ResourcesWebsite: ansible.com
Documentation: docs.ansible.com
Twitter: @ansible
IRC: #ansible (freenode)
Google Group: ansible-project
Reddit: reddit.com/r/ansible
Ansible Weekly Newsletter: devopsu.com
Ansible Configuration Management:
(Daniel Hall: Packt Publishing Nov ’13 ISBN 978-1-78328-081-0)
@magma_digital
๏ Jeremy Coates, MD at Magma Digital Ltd
๏ Founder of PHPNW
๏ Manchester Digital Association Council Member
๏ @phpcodemonkey
๏ linkedin.com/in/jeremycoates
http://bit.ly/orchestrate_infrastructure
Simply Orchestratehttps://joind.in/11296
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
OctocamOctocam
Octocam
ConvegnoAsstra626 views
Feria Julio 2014 ValenciaFeria Julio 2014 Valencia
Feria Julio 2014 Valencia
Plaza De Toros Valencia366 views
SUNRISE CITYSUNRISE CITY
SUNRISE CITY
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
PhingPhing
Phing
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