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

DevOps Meetup ansible
DevOps Meetup   ansibleDevOps Meetup   ansible
DevOps Meetup ansiblesriram_rajan
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
 
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3Ji-Woong Choi
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationJohn Lynch
 
Backup and Restore VMs Based on KVM
Backup and Restore VMs Based on KVMBackup and Restore VMs Based on KVM
Backup and Restore VMs Based on KVMShapeBlue
 
Zabbix Performance Tuning
Zabbix Performance TuningZabbix Performance Tuning
Zabbix Performance TuningRicardo Santos
 
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...Simplilearn
 
Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...
Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...
Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...Henning Jacobs
 
Alexei Vladishev - Zabbix - Monitoring Solution for Everyone
Alexei Vladishev - Zabbix - Monitoring Solution for EveryoneAlexei Vladishev - Zabbix - Monitoring Solution for Everyone
Alexei Vladishev - Zabbix - Monitoring Solution for EveryoneZabbix
 
Automate DBA Tasks With Ansible
Automate DBA Tasks With AnsibleAutomate DBA Tasks With Ansible
Automate DBA Tasks With AnsibleIvica Arsov
 
Instana - ClickHouse presentation
Instana - ClickHouse presentationInstana - ClickHouse presentation
Instana - ClickHouse presentationMiel Donkers
 
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)I Goo Lee
 
Monitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with ZabbixMonitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with ZabbixGerger
 
Containerd internals: building a core container runtime
Containerd internals: building a core container runtimeContainerd internals: building a core container runtime
Containerd internals: building a core container runtimeDocker, Inc.
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleCoreStack
 

What's hot (20)

DevOps Meetup ansible
DevOps Meetup   ansibleDevOps Meetup   ansible
DevOps Meetup ansible
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Container Networking Deep Dive
Container Networking Deep DiveContainer Networking Deep Dive
Container Networking Deep Dive
 
Backup and Restore VMs Based on KVM
Backup and Restore VMs Based on KVMBackup and Restore VMs Based on KVM
Backup and Restore VMs Based on KVM
 
Zabbix Performance Tuning
Zabbix Performance TuningZabbix Performance Tuning
Zabbix Performance Tuning
 
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
 
Ansible Automation - Enterprise Use Cases | Juncheng Anthony Lin
Ansible Automation - Enterprise Use Cases | Juncheng Anthony LinAnsible Automation - Enterprise Use Cases | Juncheng Anthony Lin
Ansible Automation - Enterprise Use Cases | Juncheng Anthony Lin
 
Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...
Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...
Running Kubernetes in Production: A Million Ways to Crash Your Cluster - DevO...
 
Ansible
AnsibleAnsible
Ansible
 
Alexei Vladishev - Zabbix - Monitoring Solution for Everyone
Alexei Vladishev - Zabbix - Monitoring Solution for EveryoneAlexei Vladishev - Zabbix - Monitoring Solution for Everyone
Alexei Vladishev - Zabbix - Monitoring Solution for Everyone
 
Automate DBA Tasks With Ansible
Automate DBA Tasks With AnsibleAutomate DBA Tasks With Ansible
Automate DBA Tasks With Ansible
 
Ansible
AnsibleAnsible
Ansible
 
Instana - ClickHouse presentation
Instana - ClickHouse presentationInstana - ClickHouse presentation
Instana - ClickHouse presentation
 
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
오픈소스로 만드는 DB 모니터링 시스템 (w/graphite+grafana)
 
Monitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with ZabbixMonitoring Oracle Database Instances with Zabbix
Monitoring Oracle Database Instances with Zabbix
 
Linux networking
Linux networkingLinux networking
Linux networking
 
Containerd internals: building a core container runtime
Containerd internals: building a core container runtimeContainerd internals: building a core container runtime
Containerd internals: building a core container runtime
 
Introduction to Ansible
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
 

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
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102APNIC
 
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
 

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
 
Stacki - The1600+ Server Journey
Stacki - The1600+ Server JourneyStacki - The1600+ Server Journey
Stacki - The1600+ Server Journey
 
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
 
(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
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
 
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
 

Recently uploaded

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
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-...Steffen Staab
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
+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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Recently uploaded (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
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-...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
+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...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

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!