SlideShare a Scribd company logo
1 of 66
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Brown bag - Crash course
Automation makes IT better
@soldasimo
simonesoldateschi
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Agenda
● Presentation (20’)
o The basics
o Playbooks
o Sharing code
● Q&A (5’)
● Quiz (5’)
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
The basics
Installation on management host:
$ pip install ansible
That’s it!
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
The basics
Installing agent on
managed hosts:
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
The basics
Can be as simple as:
mail.example.com
or:
10.1.157.183
Create an inventory file
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
The basics
Is host alive?
$ ansible -i ~/etc/hosts all -m ping
Ansible - Quickstart
ss-dfw-00 | success >> {
"changed": false,
"ping": "pong"
}
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
The basics
Tons of servers to run commands on?
$ ansible -i ~/etc/hosts all -m shell -a 'df -h'
Ansible - Quickstart
ss-dfw-00 | success | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
rootfs 20G 1.6G 18G 9% /
udev 10M 0 10M 0% /dev
...
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
A few facts about Ansible
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
A few facts about Ansible
● open-source
● free-software (GPL v3)
● written in Python
● agent-less
● push model ← K.I.S.S.
● commercial version
...OK, SSH is an agent ;)
● enterprise support, SLA, …
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Why use ansible?
Automate repetitive tasks
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Inventory
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Inventory - Hosts and Groups
mail.example.com
10.1.157.183
[webservers]
foo.example.com
bar.example.com
[dbservers]
one.example.com
two.example.com
three.example.com
$ ansible -i /path/to/inventory
GROUP_NAME …
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Inventory - Hosts and Groups
ss-dfw-00
10.182.37.244
$ ansible -i ~/etc/hosts all --sudo -m command -a 'aptitude update'
ss-dfw-00 | success | rc=0 >>
Get: 1 http://mirror.rackspace.com wheezy Release.gpg [1672 B]
Get: 2 http://mirror.rackspace.com wheezy/updates Release.gpg [836 B]
Get: 3 http://mirror.rackspace.com wheezy-backports Release.gpg [836 B]
…
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Inventory - Hosts and Groups
[webservers]
foo.example.com
bar.example.com
[dbservers]
one.example.com
two.example.com
three.example.com
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Inventory - Hosts and Groups
$ ansible -i hosts webserver -f10 
-m command 
-a ‘aptitude install apache2’
[webservers]
foo.example.com
bar.example.com
[dbservers]
one.example.com
two.example.com
three.example.com
$ ansible -i hosts dbserver -f10 
-m command 
-a ‘aptitude install mysql’
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Inventory - Hosts and Groups
[webservers]
foo.example.com
bar.example.com
[dbservers]
foo.example.com
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Inventory - Hosts and Groups
[webservers]
www[01:10].example.com
bar.example.com
[dbservers]
db-[a:f].example.com
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Inventory - Hosts variables
[atlanta]
host1 http_port=80 maxRequestsPerChild=808
host2 http_port=303 maxRequestsPerChild=909
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Modules
What can modules do?
● run commands
● transfer files
● install packages
● manage daemons
● manage users and groups
● gather facts
● deploy software with SCM
● manage DBs (MySQL,
PostgreSQL, MongoDB,
Redis, …)
● manage Cloud devices
See:
http://docs.ansible.com/modules_by_category.html
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Desired State
Go live!
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Desired state
Write code to tell the computer
how to set up itself!
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Agenda
● Presentation (20’)
o The basics
o Playbooks
o Sharing code
● Q&A (5’)
● Quiz (5’)
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks
● Contain one or more plays
● Written in YAML
○ declarative config
○ not code
● Executed in the order it is
written (aka Imperative)
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks
---
- name: deploy web server
user: foouser
sudo: True
hosts: all
tasks:
- name: install apache
apt: pkg=apache2-mpm-prefork state=latest
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks
---
- name: deploy web server
user: foouser
sudo: True
hosts: all
tasks:
- name: install apache
apt: pkg=apache2-mpm-prefork state=latest
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks
---
- name: deploy web server
user: foouser
sudo: True
hosts: all
tasks:
- name: install apache
apt: pkg=apache2-mpm-prefork state=latest
Inventory
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks
---
- name: deploy web server
user: foouser
sudo: True
hosts: all
tasks:
- name: install apache
apt: pkg=apache2-mpm-prefork state=latest
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks
---
- name: deploy web server
user: foouser
sudo: True
hosts: all
tasks:
- name: install apache
apt: pkg=apache2-mpm-prefork state=latest
Documentation
Arguments
Module
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - output
$ ansible-playbook -i ~/etc/hosts main.yml
PLAY [deploy web server] ******************************************************
GATHERING FACTS ***************************************************************
ok: [ss-dfw-00]
TASK: [install apache] ********************************************************
changed: [ss-dfw-00]
PLAY RECAP ********************************************************************
ss-dfw-00 : ok=2 changed=1 unreachable=0 failed=0
foouser@ss-dfw-00:~$ sudo netstat -putan | grep 80
tcp6 0 0 :::80 :::* LISTEN
11306/apache2
Desired state
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - output
$ ansible-playbook -i ~/etc/hosts main.yml
PLAY [deploy web server] ******************************************************
GATHERING FACTS ***************************************************************
ok: [ss-dfw-00]
TASK: [install apache] ********************************************************
changed: [ss-dfw-00]
PLAY RECAP ********************************************************************
ss-dfw-00 : ok=2 changed=1 unreachable=0 failed=0
foouser@ss-dfw-00:~$ sudo netstat -putan | grep 80
tcp6 0 0 :::80 :::* LISTEN
11306/apache2
NOT Desired state
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks
Idempotency
1 * N 0 + N
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - output
$ ansible-playbook -i ~/etc/hosts main.yml
PLAY [deploy web server] ******************************************************
GATHERING FACTS ***************************************************************
ok: [ss-dfw-00]
TASK: [install apache] ********************************************************
ok: [ss-dfw-00]
PLAY RECAP ********************************************************************
ss-dfw-00 : ok=2 changed=0 unreachable=0 failed=0
Idempotency
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Conditionals
---
.
.
.
tasks:
- name: install apache on Debian based distros
apt: pkg=apache2-mpm-prefork state=latest
when: ansible_os_family=="Debian"
- name: install apache on Red-Hat based distros
yum: pkg=httpd state=latest
when: ansible_os_family=="RedHat"
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Conditionals
---
.
.
.
tasks:
- name: install apache on Debian based distros
apt: pkg=apache2-mpm-prefork state=latest
when: ansible_os_family=="Debian"
- name: install apache on Red-Hat based distros
yum: pkg=httpd state=latest
when: ansible_os_family=="RedHat"
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Includes
---
.
.
.
tasks:
- include: apache_debian.yml
when: ansible_os_family=="Debian"
- include: apache_redhat.yml
when: ansible_os_family=="RedHat"
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Includes
---
.
.
.
tasks:
- include: apache_debian.yml
when: ansible_os_family=="Debian"
- include: apache_redhat.yml
when: ansible_os_family=="RedHat"
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Includes
---
# apache_debian.yml
tasks:
- name: install apache on Debian based distros
apt: pkg=apache2-mpm-prefork state=latest
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Includes
---
# apache_redhat.yml
tasks:
- name: install apache on Red-Hat based distros
yum: pkg=httpd state=latest
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Deploy LAMP
Let’s deploy LAMP with Ansible!
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Groups of servers
webservers dbservers
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Deploy LAMP
Inventory file
[webservers]
web0
web1
[dbservers]
db0
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Deploy LAMP
roles
common
db
web
lamp_simple
---
# This playbook deploys the whole application stack in this
site.
- name: apply common configuration to all nodes
hosts: all
user: root
roles:
- common
- name: configure and deploy the webservers and application
code
hosts: webservers
user: root
roles:
- web
- name: deploy MySQL and configure the databases
hosts: dbservers
user: root
roles:
- db
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Deploy LAMP
roles
common
db
web
lamp_simple
---
# This playbook deploys the whole application stack in this
site.
- name: apply common configuration to all nodes
hosts: all
user: root
roles:
- common
- name: configure and deploy the webservers and application
code
hosts: webservers
user: root
roles:
- web
- name: deploy MySQL and configure the databases
hosts: dbservers
user: root
roles:
- db
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Deploy LAMP
roles
common
db
web
lamp_simple
---
# This playbook deploys the whole application stack in this
site.
- name: apply common configuration to all nodes
hosts: all
user: root
roles:
- common
- name: configure and deploy the webservers and application
code
hosts: webservers
user: root
roles:
- web
- name: deploy MySQL and configure the databases
hosts: dbservers
user: root
roles:
- db
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Deploy LAMP
common
tasks
db
tasks
web
tasks
playbooks
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Deploy LAMP
common
tasks
---
# This playbook contains common plays that will be run on all nodes.
- name: Install ntp
yum: name=ntp state=present
tags: ntp
- name: Configure ntp file
template: src=ntp.conf.j2 dest=/etc/ntp.conf
tags: ntp
notify: restart ntp
…
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Deploy LAMP
db
tasks
---
# This playbook will install mysql
# and create db user and give permissions.
- name: Install Mysql package
yum: name={{ item }} state=installed
with_items:
- mysql-server
- MySQL-python
- libselinux-python
- libsemanage-python
…
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Playbooks - Deploy LAMP
web
tasks
---
# These tasks install http and the php modules.
- name: Install http and php etc
yum: name={{ item }} state=present
with_items:
- httpd
- php
- php-mysql
- …
- name: insert iptables rule for httpd
lineinfile: dest=/etc/sysconfig/iptables create=yes state=present
regexp="{{ httpd_port }}" insertafter="^:OUTPUT "
line="-A INPUT -p tcp --dport {{ httpd_port }} -j
ACCEPT"
notify: restart iptables
…
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Best practices - Directory layout
site.yml # master playbook
webservers.yml # playbook for webserver tier
dbservers.yml # playbook for dbserver tier
roles/
common/ # this hierarchy represents a "role"
tasks/ #
main.yml # <-- tasks file can include smaller files if warranted
handlers/ #
main.yml # <-- handlers file
templates/ # <-- files for use with the template resource
ntp.conf.j2 # <------- templates end in .j2
files/ #
bar.txt # <-- files for use with the copy resource
foo.sh # <-- script files for use with the script resource
vars/ #
main.yml # <-- variables associated with this role
webtier/ # same kind of structure as "common" was above, done for the webtier role
monitoring/ # ""
fooapp/ # ""
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Agenda
● Presentation (20’)
o The basics
o Playbooks
o Sharing code
● Q&A (5’)
● Quiz (5’)
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Sharing playbooks
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Sharing playbooks
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Sharing playbooks
$ git clone https://github.com/ansible/ansible-examples
Cloning into 'ansible-examples'...
remote: Reusing existing pack: 1698, done.
remote: Total 1698 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1698/1698), 3.73 MiB | 296.00
KiB/s, done.
Resolving deltas: 100% (355/355), done.
Checking connectivity... done
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Sharing playbooks
$ ansible-playbook -i ~/etc/hosts lamp_simple/site.yml
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Sharing playbooks
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Sharing code
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Agenda
● Presentation (20’)
o The basics
o Playbooks
o Git repositories
● Q&A (5’)
● Quiz (5’)
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Agenda
● Presentation (20’)
o The basics
o Playbooks
o Git repositories
● Q&A (5’)
● Quiz (5’)
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Quiz
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Give your feedback!
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
References
Ansible Workshttp://www.ansible.com/home
Ansible
Documentationhttp://docs.ansible.com/inde
x.html
Ansible source
codehttps://github.com/ansible/ansible
Ansible
exampleshttps://github.com/ansible/ansible-
examples
Best
practiceshttp://docs.ansible.com/
playbooks_best_practices.html
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
Homework
● Replay examples
● commit result to GitHub
● send me a message
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
@soldasimo
simonesoldateschi

More Related Content

What's hot

Hacking ansible
Hacking ansibleHacking ansible
Hacking ansiblebcoca
 
PyCon Russia 2014 - Auto Scale in the Cloud
PyCon Russia 2014 - Auto Scale in the CloudPyCon Russia 2014 - Auto Scale in the Cloud
PyCon Russia 2014 - Auto Scale in the CloudSimone Soldateschi
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationJohn Lynch
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0bcoca
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricksbcoca
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them AllTim Fairweather
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102APNIC
 
Ansible Introduction - Ansible Brno #1 - David Karban
Ansible Introduction - Ansible Brno #1 - David KarbanAnsible Introduction - Ansible Brno #1 - David Karban
Ansible Introduction - Ansible Brno #1 - David Karbanansiblebrno
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Brian Schott
 
Ansible basics workshop
Ansible basics workshopAnsible basics workshop
Ansible basics workshopDavid Karban
 
Ansible for beginners
Ansible for beginnersAnsible for beginners
Ansible for beginnersKuo-Le Mei
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12Keith Resar
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practicesBas Meijer
 

What's hot (20)

Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
PyCon Russia 2014 - Auto Scale in the Cloud
PyCon Russia 2014 - Auto Scale in the CloudPyCon Russia 2014 - Auto Scale in the Cloud
PyCon Russia 2014 - Auto Scale in the Cloud
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with 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
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
 
Ansible Introduction - Ansible Brno #1 - David Karban
Ansible Introduction - Ansible Brno #1 - David KarbanAnsible Introduction - Ansible Brno #1 - David Karban
Ansible Introduction - Ansible Brno #1 - David Karban
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2
 
Ansible basics workshop
Ansible basics workshopAnsible basics workshop
Ansible basics workshop
 
Ansible for beginners
Ansible for beginnersAnsible for beginners
Ansible for beginners
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
ansible why ?
ansible why ?ansible why ?
ansible why ?
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practices
 

Similar to Ansible - Crash course

Building cloud stack at scale
Building cloud stack at scaleBuilding cloud stack at scale
Building cloud stack at scaleShapeBlue
 
StackiFest16: Stacki 1600+ Server Journey - Dave Peterson, Salesforce
StackiFest16: Stacki 1600+ Server Journey - Dave Peterson, Salesforce StackiFest16: Stacki 1600+ Server Journey - Dave Peterson, Salesforce
StackiFest16: Stacki 1600+ Server Journey - Dave Peterson, Salesforce StackIQ
 
(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014
(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014
(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014Amazon Web Services
 
Salesforce at Stacki Atlanta Meetup February 2016
Salesforce at Stacki Atlanta Meetup February 2016Salesforce at Stacki Atlanta Meetup February 2016
Salesforce at Stacki Atlanta Meetup February 2016StackIQ
 
Rackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & PackerRackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & PackerMarc Cluet
 
Asynchronous Threads in Lasso 8.5
Asynchronous Threads in Lasso 8.5Asynchronous Threads in Lasso 8.5
Asynchronous Threads in Lasso 8.5bilcorry
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by CapistranoTasawr Interactive
 
An Express Guide ~ Zabbix for IT Monitoring
An Express Guide ~ Zabbix for IT Monitoring An Express Guide ~ Zabbix for IT Monitoring
An Express Guide ~ Zabbix for IT Monitoring Abhishek Kumar
 
Be a Cloud Native
Be a Cloud NativeBe a Cloud Native
Be a Cloud NativeInnoTech
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShellDale Lane
 
Consideration for Building a Private Cloud
Consideration for Building a Private CloudConsideration for Building a Private Cloud
Consideration for Building a Private CloudOpenStack Foundation
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionSysdig
 
Stacki: Remove Commands
Stacki: Remove CommandsStacki: Remove Commands
Stacki: Remove CommandsStackIQ
 
The Mission Critical Cloud @ Apache CloudStack meetup Amsterdam June 2015
The Mission Critical Cloud @ Apache CloudStack meetup Amsterdam June 2015The Mission Critical Cloud @ Apache CloudStack meetup Amsterdam June 2015
The Mission Critical Cloud @ Apache CloudStack meetup Amsterdam June 2015Remi Bergsma
 
Basic Knowledge on MySql Replication
Basic Knowledge on MySql ReplicationBasic Knowledge on MySql Replication
Basic Knowledge on MySql ReplicationTasawr Interactive
 

Similar to Ansible - Crash course (20)

Building cloud stack at scale
Building cloud stack at scaleBuilding cloud stack at scale
Building cloud stack at scale
 
StackiFest16: Stacki 1600+ Server Journey - Dave Peterson, Salesforce
StackiFest16: Stacki 1600+ Server Journey - Dave Peterson, Salesforce StackiFest16: Stacki 1600+ Server Journey - Dave Peterson, Salesforce
StackiFest16: Stacki 1600+ Server Journey - Dave Peterson, Salesforce
 
Stacki - The1600+ Server Journey
Stacki - The1600+ Server JourneyStacki - The1600+ Server Journey
Stacki - The1600+ Server Journey
 
(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014
(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014
(WEB302) Best Practices for Running WordPress on AWS | AWS re:Invent 2014
 
Salesforce at Stacki Atlanta Meetup February 2016
Salesforce at Stacki Atlanta Meetup February 2016Salesforce at Stacki Atlanta Meetup February 2016
Salesforce at Stacki Atlanta Meetup February 2016
 
Rackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & PackerRackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & Packer
 
Asynchronous Threads in Lasso 8.5
Asynchronous Threads in Lasso 8.5Asynchronous Threads in Lasso 8.5
Asynchronous Threads in Lasso 8.5
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
An Express Guide ~ Zabbix for IT Monitoring
An Express Guide ~ Zabbix for IT Monitoring An Express Guide ~ Zabbix for IT Monitoring
An Express Guide ~ Zabbix for IT Monitoring
 
Git Crash Course
Git Crash CourseGit Crash Course
Git Crash Course
 
Be a Cloud Native
Be a Cloud NativeBe a Cloud Native
Be a Cloud Native
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
 
Consideration for Building a Private Cloud
Consideration for Building a Private CloudConsideration for Building a Private Cloud
Consideration for Building a Private Cloud
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccion
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
Stacki: Remove Commands
Stacki: Remove CommandsStacki: Remove Commands
Stacki: Remove Commands
 
The Mission Critical Cloud @ Apache CloudStack meetup Amsterdam June 2015
The Mission Critical Cloud @ Apache CloudStack meetup Amsterdam June 2015The Mission Critical Cloud @ Apache CloudStack meetup Amsterdam June 2015
The Mission Critical Cloud @ Apache CloudStack meetup Amsterdam June 2015
 
Network Manual
Network ManualNetwork Manual
Network Manual
 
Basic Knowledge on MySql Replication
Basic Knowledge on MySql ReplicationBasic Knowledge on MySql Replication
Basic Knowledge on MySql Replication
 

Recently uploaded

UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 

Recently uploaded (20)

UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 

Ansible - Crash course

  • 1. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Brown bag - Crash course Automation makes IT better @soldasimo simonesoldateschi
  • 2. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda ● Presentation (20’) o The basics o Playbooks o Sharing code ● Q&A (5’) ● Quiz (5’)
  • 3. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk The basics Installation on management host: $ pip install ansible That’s it!
  • 4. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk The basics Installing agent on managed hosts:
  • 5. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk The basics Can be as simple as: mail.example.com or: 10.1.157.183 Create an inventory file
  • 6. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk The basics Is host alive? $ ansible -i ~/etc/hosts all -m ping Ansible - Quickstart ss-dfw-00 | success >> { "changed": false, "ping": "pong" }
  • 7. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk The basics Tons of servers to run commands on? $ ansible -i ~/etc/hosts all -m shell -a 'df -h' Ansible - Quickstart ss-dfw-00 | success | rc=0 >> Filesystem Size Used Avail Use% Mounted on rootfs 20G 1.6G 18G 9% / udev 10M 0 10M 0% /dev ...
  • 8. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk A few facts about Ansible
  • 9. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk A few facts about Ansible ● open-source ● free-software (GPL v3) ● written in Python ● agent-less ● push model ← K.I.S.S. ● commercial version ...OK, SSH is an agent ;) ● enterprise support, SLA, …
  • 10. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Why use ansible? Automate repetitive tasks
  • 11. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Inventory
  • 12. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Inventory - Hosts and Groups mail.example.com 10.1.157.183 [webservers] foo.example.com bar.example.com [dbservers] one.example.com two.example.com three.example.com $ ansible -i /path/to/inventory GROUP_NAME …
  • 13. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Inventory - Hosts and Groups ss-dfw-00 10.182.37.244 $ ansible -i ~/etc/hosts all --sudo -m command -a 'aptitude update' ss-dfw-00 | success | rc=0 >> Get: 1 http://mirror.rackspace.com wheezy Release.gpg [1672 B] Get: 2 http://mirror.rackspace.com wheezy/updates Release.gpg [836 B] Get: 3 http://mirror.rackspace.com wheezy-backports Release.gpg [836 B] …
  • 14. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Inventory - Hosts and Groups [webservers] foo.example.com bar.example.com [dbservers] one.example.com two.example.com three.example.com
  • 15. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Inventory - Hosts and Groups $ ansible -i hosts webserver -f10 -m command -a ‘aptitude install apache2’ [webservers] foo.example.com bar.example.com [dbservers] one.example.com two.example.com three.example.com $ ansible -i hosts dbserver -f10 -m command -a ‘aptitude install mysql’
  • 16. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Inventory - Hosts and Groups [webservers] foo.example.com bar.example.com [dbservers] foo.example.com
  • 17. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Inventory - Hosts and Groups [webservers] www[01:10].example.com bar.example.com [dbservers] db-[a:f].example.com
  • 18. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Inventory - Hosts variables [atlanta] host1 http_port=80 maxRequestsPerChild=808 host2 http_port=303 maxRequestsPerChild=909
  • 19. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Modules What can modules do? ● run commands ● transfer files ● install packages ● manage daemons ● manage users and groups ● gather facts ● deploy software with SCM ● manage DBs (MySQL, PostgreSQL, MongoDB, Redis, …) ● manage Cloud devices See: http://docs.ansible.com/modules_by_category.html
  • 20. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Desired State Go live!
  • 21. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Desired state Write code to tell the computer how to set up itself!
  • 22. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda ● Presentation (20’) o The basics o Playbooks o Sharing code ● Q&A (5’) ● Quiz (5’)
  • 23. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks ● Contain one or more plays ● Written in YAML ○ declarative config ○ not code ● Executed in the order it is written (aka Imperative)
  • 24. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks --- - name: deploy web server user: foouser sudo: True hosts: all tasks: - name: install apache apt: pkg=apache2-mpm-prefork state=latest
  • 25. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks --- - name: deploy web server user: foouser sudo: True hosts: all tasks: - name: install apache apt: pkg=apache2-mpm-prefork state=latest
  • 26. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks --- - name: deploy web server user: foouser sudo: True hosts: all tasks: - name: install apache apt: pkg=apache2-mpm-prefork state=latest Inventory
  • 27. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks --- - name: deploy web server user: foouser sudo: True hosts: all tasks: - name: install apache apt: pkg=apache2-mpm-prefork state=latest
  • 28. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks --- - name: deploy web server user: foouser sudo: True hosts: all tasks: - name: install apache apt: pkg=apache2-mpm-prefork state=latest Documentation Arguments Module
  • 29. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - output $ ansible-playbook -i ~/etc/hosts main.yml PLAY [deploy web server] ****************************************************** GATHERING FACTS *************************************************************** ok: [ss-dfw-00] TASK: [install apache] ******************************************************** changed: [ss-dfw-00] PLAY RECAP ******************************************************************** ss-dfw-00 : ok=2 changed=1 unreachable=0 failed=0 foouser@ss-dfw-00:~$ sudo netstat -putan | grep 80 tcp6 0 0 :::80 :::* LISTEN 11306/apache2 Desired state
  • 30. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - output $ ansible-playbook -i ~/etc/hosts main.yml PLAY [deploy web server] ****************************************************** GATHERING FACTS *************************************************************** ok: [ss-dfw-00] TASK: [install apache] ******************************************************** changed: [ss-dfw-00] PLAY RECAP ******************************************************************** ss-dfw-00 : ok=2 changed=1 unreachable=0 failed=0 foouser@ss-dfw-00:~$ sudo netstat -putan | grep 80 tcp6 0 0 :::80 :::* LISTEN 11306/apache2 NOT Desired state
  • 31. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks Idempotency 1 * N 0 + N
  • 32. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - output $ ansible-playbook -i ~/etc/hosts main.yml PLAY [deploy web server] ****************************************************** GATHERING FACTS *************************************************************** ok: [ss-dfw-00] TASK: [install apache] ******************************************************** ok: [ss-dfw-00] PLAY RECAP ******************************************************************** ss-dfw-00 : ok=2 changed=0 unreachable=0 failed=0 Idempotency
  • 33. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Conditionals --- . . . tasks: - name: install apache on Debian based distros apt: pkg=apache2-mpm-prefork state=latest when: ansible_os_family=="Debian" - name: install apache on Red-Hat based distros yum: pkg=httpd state=latest when: ansible_os_family=="RedHat"
  • 34. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Conditionals --- . . . tasks: - name: install apache on Debian based distros apt: pkg=apache2-mpm-prefork state=latest when: ansible_os_family=="Debian" - name: install apache on Red-Hat based distros yum: pkg=httpd state=latest when: ansible_os_family=="RedHat"
  • 35. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Includes --- . . . tasks: - include: apache_debian.yml when: ansible_os_family=="Debian" - include: apache_redhat.yml when: ansible_os_family=="RedHat"
  • 36. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Includes --- . . . tasks: - include: apache_debian.yml when: ansible_os_family=="Debian" - include: apache_redhat.yml when: ansible_os_family=="RedHat"
  • 37. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Includes --- # apache_debian.yml tasks: - name: install apache on Debian based distros apt: pkg=apache2-mpm-prefork state=latest
  • 38. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Includes --- # apache_redhat.yml tasks: - name: install apache on Red-Hat based distros yum: pkg=httpd state=latest
  • 39. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Deploy LAMP Let’s deploy LAMP with Ansible!
  • 40. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Groups of servers webservers dbservers
  • 41. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Deploy LAMP Inventory file [webservers] web0 web1 [dbservers] db0
  • 42. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Deploy LAMP roles common db web lamp_simple --- # This playbook deploys the whole application stack in this site. - name: apply common configuration to all nodes hosts: all user: root roles: - common - name: configure and deploy the webservers and application code hosts: webservers user: root roles: - web - name: deploy MySQL and configure the databases hosts: dbservers user: root roles: - db
  • 43. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Deploy LAMP roles common db web lamp_simple --- # This playbook deploys the whole application stack in this site. - name: apply common configuration to all nodes hosts: all user: root roles: - common - name: configure and deploy the webservers and application code hosts: webservers user: root roles: - web - name: deploy MySQL and configure the databases hosts: dbservers user: root roles: - db
  • 44. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Deploy LAMP roles common db web lamp_simple --- # This playbook deploys the whole application stack in this site. - name: apply common configuration to all nodes hosts: all user: root roles: - common - name: configure and deploy the webservers and application code hosts: webservers user: root roles: - web - name: deploy MySQL and configure the databases hosts: dbservers user: root roles: - db
  • 45. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Deploy LAMP common tasks db tasks web tasks playbooks
  • 46. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Deploy LAMP common tasks --- # This playbook contains common plays that will be run on all nodes. - name: Install ntp yum: name=ntp state=present tags: ntp - name: Configure ntp file template: src=ntp.conf.j2 dest=/etc/ntp.conf tags: ntp notify: restart ntp …
  • 47. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Deploy LAMP db tasks --- # This playbook will install mysql # and create db user and give permissions. - name: Install Mysql package yum: name={{ item }} state=installed with_items: - mysql-server - MySQL-python - libselinux-python - libsemanage-python …
  • 48. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Playbooks - Deploy LAMP web tasks --- # These tasks install http and the php modules. - name: Install http and php etc yum: name={{ item }} state=present with_items: - httpd - php - php-mysql - … - name: insert iptables rule for httpd lineinfile: dest=/etc/sysconfig/iptables create=yes state=present regexp="{{ httpd_port }}" insertafter="^:OUTPUT " line="-A INPUT -p tcp --dport {{ httpd_port }} -j ACCEPT" notify: restart iptables …
  • 49. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Best practices - Directory layout site.yml # master playbook webservers.yml # playbook for webserver tier dbservers.yml # playbook for dbserver tier roles/ common/ # this hierarchy represents a "role" tasks/ # main.yml # <-- tasks file can include smaller files if warranted handlers/ # main.yml # <-- handlers file templates/ # <-- files for use with the template resource ntp.conf.j2 # <------- templates end in .j2 files/ # bar.txt # <-- files for use with the copy resource foo.sh # <-- script files for use with the script resource vars/ # main.yml # <-- variables associated with this role webtier/ # same kind of structure as "common" was above, done for the webtier role monitoring/ # "" fooapp/ # ""
  • 50. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda ● Presentation (20’) o The basics o Playbooks o Sharing code ● Q&A (5’) ● Quiz (5’)
  • 51. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Sharing playbooks
  • 52. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Sharing playbooks
  • 53. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Sharing playbooks $ git clone https://github.com/ansible/ansible-examples Cloning into 'ansible-examples'... remote: Reusing existing pack: 1698, done. remote: Total 1698 (delta 0), reused 0 (delta 0) Receiving objects: 100% (1698/1698), 3.73 MiB | 296.00 KiB/s, done. Resolving deltas: 100% (355/355), done. Checking connectivity... done
  • 54. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Sharing playbooks $ ansible-playbook -i ~/etc/hosts lamp_simple/site.yml
  • 55. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Sharing playbooks
  • 56. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Sharing code
  • 57. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
  • 58. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda ● Presentation (20’) o The basics o Playbooks o Git repositories ● Q&A (5’) ● Quiz (5’)
  • 59. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
  • 60. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Agenda ● Presentation (20’) o The basics o Playbooks o Git repositories ● Q&A (5’) ● Quiz (5’)
  • 61. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Quiz
  • 62. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Give your feedback!
  • 63. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk References Ansible Workshttp://www.ansible.com/home Ansible Documentationhttp://docs.ansible.com/inde x.html Ansible source codehttps://github.com/ansible/ansible Ansible exampleshttps://github.com/ansible/ansible- examples Best practiceshttp://docs.ansible.com/ playbooks_best_practices.html
  • 64. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk Homework ● Replay examples ● commit result to GitHub ● send me a message
  • 65. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk
  • 66. RACKSPACE® HOSTING | WWW.RACKSPACE.COMsimone.soldateschi@rackspace.co.uk @soldasimo simonesoldateschi

Editor's Notes

  1. In fact Ansible is agent-less.OK, OK, SSH is an agent ;)
  2. The inventory file references hosts to be managed. It might contain credentials and key-value pairs.
  3. ansible is the swiss-army-knife
  4. The inventory file references hosts to be managed. It might contain credentials and key-value pairs.
  5. You have many servers to manage
  6. The inventory file references hosts to be managed. It might contain credentials and key-value pairs.
  7. The inventory file references hosts to be managed. It might contain credentials and key-value pairs.
  8. The inventory file references hosts to be managed. It might contain credentials and key-value pairs. ‘-f10’ tells Ansible to fork 10 times, aka manage 10 servers in parallel
  9. The inventory file references hosts to be managed. It might contain credentials and key-value pairs. ‘-f10’ tells Ansible to fork 10 times, aka manage 10 servers in parallel
  10. foo.example.com is both a web server and a database server
  11. www01.example.com … www10.example.com are web serversdb-a.example.com … db-f.example.com are database servers
  12. Let’s install Apache HTTP server using a playbook
  13. Let’s install Apache HTTP server using a playbook
  14. all refers to all the host defined within the inventory file It could be any group-name.
  15. Let’s install Apache HTTP server using a playbook
  16. Let’s install Apache HTTP server using a playbook
  17. Let’s install Apache HTTP server using a playbook
  18. Let’s install Apache HTTP server using a playbook
  19. Let’s install Apache HTTP server using a playbook
  20. Let’s install Apache HTTP server, using the same playbook, on Debian and Red-Hat based distros.
  21. Let’s install Apache HTTP server, using the same playbook, on Debian and Red-Hat based distros.
  22. It’s possible to achieve the same result including sub-playbooks
  23. It’s possible to achieve the same result including sub-playbooks
  24. It’s possible to achieve the same result including sub-playbooks
  25. It’s possible to achieve the same result including sub-playbooks
  26. It’s possible to achieve the same result including sub-playbooks
  27. It’s possible to achieve the same result including sub-playbooks
  28. It’s possible to achieve the same result including sub-playbooks
  29. It’s possible to achieve the same result including sub-playbooks
  30. It’s possible to achieve the same result including sub-playbooks
  31. It’s possible to achieve the same result including sub-playbooks
  32. It’s possible to achieve the same result including sub-playbooks
  33. It’s possible to achieve the same result including sub-playbooks
  34. It’s possible to achieve the same result including sub-playbooks
  35. It’s possible to achieve the same result including sub-playbooks
  36. Please, give your feedback!