SlideShare a Scribd company logo
1 of 47
Download to read offline
Ansible
Systems configuration doesn't have to be complicated
Jan-Piet Mens
April 2014
@jpmens
@jpmens: consultant,
author, architect, part-time
admin, small-scale fiddler,
loves LDAP, DNS,
plain text, and things
that work.
once upon a time, we
had shell scripts and
SSH loops
then it got
complicated ...
this is what we
want:
No more daemons
No more agents
Not yet another PKI
Not another host
No more open ports
No databases
Automation should not
require programming
experience; it MUST
[RFC 2119] be easy
We all have other stuff to do, don't we?
compréhansible
welcome to
Ansible
push-based
pull possible
from zero to prod in
minutes
Python
2.6 + PyYAML, Jinja2 on manager
2.4 + simplejson on nodes
Can run in virtualenv and from git checkout
SSH
keys, Kerberos, passwords
doesn't need root
can sudo
Modus operandi
Do this once, now
ad-hoc
Install packages
yum, apt, zypper, ...
Minimal config
language
no XML, no Ruby, no ...
Inventory
$ cat ${ANSIBLE_HOSTS:-/etc/ansible/hosts}
[local]
127.0.0.1
[webservers]
www.example.com ntp=ntp1.pool.ntp.org
web[10-23].example.com
sushi ansible_ssh_host=127.0.0.1 ansible_ssh_port=222
[devservers]
a1.ww.mens.de
executable inventory
• CMDB (LDAP, SQL, etc.)
• Cobbler
• EC2, OpenStack, etc.
• make your own: JSON
Target selection
webservers
all
ldap.example.com
webservers:!web20.example.com
*.example.com
192.168.6.*
ad-hoc copy
$ ansible devservers -m copy -a 'src=resolv.conf dest=/etc/resolv.conf'
a1.ww.mens.de | success >> {
"changed": true,
"dest": "/etc/resolv.conf",
"group": "adm",
"md5sum": "c6fce6e28c46be0512eaf3b7cfdb66d7",
"mode": "0644",
"owner": "jpm",
"path": "resolv.conf",
"src": "/home/jpm/.ansible/tmp/ansible-322091977449/resolv.conf",
"state": "file"
}
facts
Plus ohai and facter if installed on node
"ansible_architecture": "x86_64",
"ansible_default_ipv4": {
"address": "192.168.1.194",
"gateway": "192.168.1.1",
"interface": "eth0",
"macaddress": "22:54:00:02:8e:0f",
},
"ansible_distribution": "CentOS",
"ansible_distribution_version": "6.2",
"ansible_fqdn": "a1.ww.mens.de",
"ansible_hostname": "a1",
"ansible_processor_count": 1,
"ansible_product_name": "KVM",
"ansible_swapfree_mb": 989,
modules
Plus many more: provisioning, contrib, etc.
add_host apt apt_key apt_repository assemble async_status
authorized_key bzr cloudformation command copy cron debug
django_manage easy_install ec2 ec2_facts ec2_vol facter fail fetch file
fireball gem get_url git group group_by hg homebrew ini_file lineinfile
lvg lvol macports mail mongodb_user mount mysql_db mysql_user
nagios netscaler ohai openbsd_pkg opkg pacman pause ping pip pkgin
postgresql_db postgresql_user rabbitmq_parameter rabbitmq_plugin
rabbitmq_user rabbitmq_vhost raw s3 script seboolean selinux service
setup shell slurp subversion supervisorctl svr4pkg sysctl template
uri user vagrant virt wait_for yum zfs
Playbooks
• YAML
• OS configuration
• APP deployment
• collections of actions using modules
• each group of actions is a play
• notification handlers
Install, configure tmux
---
- hosts: devservers
user: f2
sudo: True
vars:
editmode: vi
tasks:
- name: Install tmux package
action: yum name=tmux state=installed
- name: Configure tmux
action: template src=tmux.conf.j2 dest=/etc/tmux.conf
- name: Tell master
action: shell echo "{{ansible_fqdn}} done" >> /tmp/list
delegate_to: k4.ww.mens.de
variables
• From inventory
• In plays
• From host_vars/ files
• From group_vars/ files
• From register
---
editmode: emacs
admin: Jane Jolie
location: Bldg Z8/211
{{ templates }}
templates in Jinja2
# {{ ansible_managed }}
{# editmode is either "vi" or "emacs" #}
set -g prefix C-a
set -g status-utf8 on
setw -g mode-keys {{ editmode }}
# Ansible managed: tmux.conf.j2 modified on 2012-10-14 09:47:11 by jpm on hippo
set -g prefix C-a
set -g status-utf8 on
setw -g mode-keys vi
generate /etc/hosts
{% for k,v in hostvars.iteritems() -%}
{{ v['ansible_eth0']['ipv4']['address']}} {{ k }} 
{{ v['ansible_hostname'] }}
{% endfor %}
192.168.1.218 k4.ww.mens.de k4
192.168.1.194 a1.ww.mens.de a1
...
$LOOKUP
• files, CSV
• pipe
• Redis
• DNS TXT
• ...
delegation
pull mode
fast, faster, fireball
roles
roles/
nginx/
files/
handlers/main.yml
meta/main.yml
tasks/main.yml
templates/
vars/main.yml
---
- hosts: all
roles:
- nginx
- mysql
- { role: app, dir: '/etc/app', ntp: 'n1.example.org' }
- { role: special, when: "ansible_os_family == 'RedHat'" }
tasks:
- ...
vault
$ ansible-vault create yy.yml
Vault password:
Confirm Vault password:
$ cat yy.yml
$ANSIBLE_VAULT;1.1;AES256
13064343538613362376132363832663335626463656265333132613932363833
[...]
3539
$ ansible-playbook yy.yml
ERROR: A vault password must be specified to decrypt data
$ ansible-playbook --ask-vault-pass yy.yml
Vault password:
API: task execution
#!/usr/bin/env python
import ansible.runner
import sys
res = ansible.runner.Runner(
pattern='a1*',
module_name='command',
module_args='/usr/bin/uptime'
).run()
print res
{'dark': {}, 'contacted': {'a1.ww.mens.de': {u'changed': True, u'end': u'2012-10-22
09:07:18.327568', u'stdout': u'09:07:18 up 100 days, 2:13, 3 users, load average:
0.00, 0.00, 0.00', u'cmd': [u'/usr/bin/uptime'], u'rc': 0, u'start': u'2012-10-22
09:07:18.323645', u'stderr': u'', u'delta': u'0:00:00.003923', 'invocation':
{'module_name': u'command', 'module_args': u'/usr/bin/uptime'}}}}
Extansible
• Callbacks (Python)
• Action plugins (Python)
• Data sources (Python)
• Inventory sources (any language)
ansible galaxy
• reusable roles
• New command: ansible-galaxy
More time for stuff
that matters
ansible.com
@ansible
Join the party!

More Related Content

What's hot

How we setup Rsync-powered Incremental Backups
How we setup Rsync-powered Incremental BackupsHow we setup Rsync-powered Incremental Backups
How we setup Rsync-powered Incremental Backups
nicholaspaun
 

What's hot (20)

Effective service and resource management with systemd
Effective service and resource management with systemdEffective service and resource management with systemd
Effective service and resource management with systemd
 
Linux Backup System using rsync, tar, gzip
Linux Backup System using rsync, tar, gzipLinux Backup System using rsync, tar, gzip
Linux Backup System using rsync, tar, gzip
 
Ansible with-junos
Ansible with-junosAnsible with-junos
Ansible with-junos
 
Docker puppetcamp london 2013
Docker puppetcamp london 2013Docker puppetcamp london 2013
Docker puppetcamp london 2013
 
How we setup Rsync-powered Incremental Backups
How we setup Rsync-powered Incremental BackupsHow we setup Rsync-powered Incremental Backups
How we setup Rsync-powered Incremental Backups
 
Test driven infrastructure
Test driven infrastructureTest driven infrastructure
Test driven infrastructure
 
Docker command
Docker commandDocker command
Docker command
 
DevOps Braga #6
DevOps Braga #6DevOps Braga #6
DevOps Braga #6
 
Linux kernel memory allocators
Linux kernel memory allocatorsLinux kernel memory allocators
Linux kernel memory allocators
 
Vagrant - Version control your dev environment
Vagrant - Version control your dev environmentVagrant - Version control your dev environment
Vagrant - Version control your dev environment
 
Docker, c'est bonheur !
Docker, c'est bonheur !Docker, c'est bonheur !
Docker, c'est bonheur !
 
Docker remote-api
Docker remote-apiDocker remote-api
Docker remote-api
 
Docker up and running
Docker up and runningDocker up and running
Docker up and running
 
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and ChefScaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
 
Configuration Management with Cfengine
Configuration Management with CfengineConfiguration Management with Cfengine
Configuration Management with Cfengine
 
Red hat lvm cheatsheet
Red hat   lvm cheatsheetRed hat   lvm cheatsheet
Red hat lvm cheatsheet
 
Docker / Ansible
Docker / AnsibleDocker / Ansible
Docker / Ansible
 
Virtualization with Vagrant (ua.pycon 2011)
Virtualization with Vagrant (ua.pycon 2011)Virtualization with Vagrant (ua.pycon 2011)
Virtualization with Vagrant (ua.pycon 2011)
 
Automated reproducible images on openstack using vagrant and packer
Automated reproducible images on openstack using vagrant and packerAutomated reproducible images on openstack using vagrant and packer
Automated reproducible images on openstack using vagrant and packer
 
Minicurso de Vagrant
Minicurso de VagrantMinicurso de Vagrant
Minicurso de Vagrant
 

Similar to OSDC 2014: Jan-Piet Mens - Configuration Management with Ansible

Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
Omar Reygaert
 

Similar to OSDC 2014: Jan-Piet Mens - Configuration Management with Ansible (20)

A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of Ansible
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 
Automating with Ansible
Automating with AnsibleAutomating with Ansible
Automating with Ansible
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratch
 
Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
Ansible 101
Ansible 101Ansible 101
Ansible 101
 
Ansible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaAnsible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy Mykhailiuta
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Our Puppet Story (Linuxtag 2014)
Our Puppet Story (Linuxtag 2014)Our Puppet Story (Linuxtag 2014)
Our Puppet Story (Linuxtag 2014)
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
How I hack on puppet modules
How I hack on puppet modulesHow I hack on puppet modules
How I hack on puppet modules
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
 
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
Continuous Delivery Workshop with Ansible x GitLab CI (2nd+)
 
Managing your Minions with Func
Managing your Minions with FuncManaging your Minions with Func
Managing your Minions with Func
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015
 

Recently uploaded

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 

OSDC 2014: Jan-Piet Mens - Configuration Management with Ansible