A tour of Ansible

DevOps Ltd.
DevOps Ltd.DevOps and Delivery Consultant um DevOps Ltd.
Provisioning, Config, Execution, (more) Fun
Steve Pereira
18 years in IT
Startups and Enterprise
Love learning about,
teaching and talking about:
• DevOps
• CI/CD
• Automation
• Scale
WHO AM I?
ANSIBLE FEATURES
• Automation for local and remote system provisioning
• Automation for local and remote applications deployment
• No agents to install on remote systems
• Using existing SSHd on remote systems and native SSH on host
• Parallel by default - scale to 6000 targets with single master
• Language that approaches plain english
ANSIBLE CONVENTIONS
Playbooks - contain required tasks to configure systems and deploy
Tasks - individual actions to perform on remote or local machines
Roles - modular, single-purpose configurations for systems
Inventory - files containing address information of target machines
Handlers - actions triggered by tasks
Templates - customizable files destined for managed machines
MINIMUM VIABLE ANSIBLE
$ ansible all -i 'localhost,' -c local -m ping
localhost | success >> {
"changed": false,
"ping": "pong"
}
WHAT ELSE?
• ansible webservers -m setup
• ansible lb -m copy -a "src=hosts dest=/tmp/hosts”
• ansible webservers -m yum -a "name=curl state=installed”
• ansible webservers -m service -a "name=nginx
state=restarted”
• ansible-doc -l
PLAYBOOKS---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
example_playbook.yml
PLAYBOOKS---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
example_playbook.yml
PLAYBOOKS---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
example_playbook.yml
PLAYBOOKS---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
example_playbook.yml
PLAYBOOKS---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
example_playbook.yml
PLAYBOOKS---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
example_playbook.yml
PLAYBOOKS---
- hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
example_playbook.yml
ROLES
my_role/
README.md (readme)
defaults/ (default values)
meta/ (role metadata)
files/ (binaries)
templates/ (file templates)
handlers/ (operation handlers)
tasks/ (playbook files)
vars/ (custom variables)
• Easily packaged and shared
• Download community roles
• Mix and match
INVENTORY
• Define how ansible will interact with remote hosts
• Define logical groups of managed nodes
• One file for each environment
• Default location : /etc/ansible/hosts
• INI format, variable overrides
sample_inventory.ini [loadbalancers]
10.20.30.41
10.20.30.42
[webservers]
10.20.30.51 hostname=artemis
10.20.30.52 hostname=apollo
TEMPLATES
• Use Jinja2 templating and variables to customize
• Defaults available when variables not provided (dev default with prod override)
etc_logrotate.d.j2 {{ logfile }} {
rotate {{ 7 | rotate_max }}
{{ daily | frequency }}
compress
missingok
notifempty
}
IT CAN GET FANCY
tasks:
- name: install packages in a users virtualenv
  shell: su - c {{ item[0] }} '(. ./bin/activate && pip install {{ item[1] }})'
  with_nested:
      - [ 'jim', 'joe', 'jack' ]
      - [ package1==1.1,
          package2==1.2,
          package3==1.3 ]
There are several types of loops:
Hashes, Fileglobs, Sequence, Subelements, First match, Command results, Random and
more
but there’s a builtin pip module, anyways.
CONDITIONALS
tasks:
- command: /bin/false
register: result
ignore_errors:True
- command: /bin/something
when: result|failed
- command: /bin/something_else
when: result|success
- command: /bin/still/something_else
when: result|skipped
The result of a play can depend on
the value of a variable, fact
(something learned about the
remote system), or previous task
result.
MORE CONDITIONALS!
tasks:
- shell: echo "I've got '{{ foo }}'"
when: foo is defined
- fail: msg="This play requires 'bar'"
when: bar is not defined
- command: echo {{ item }}
with_items: [ 0, 2, 4, 6, 8, 10 ]
when: item > 5
If a required variable has not been
set, you can skip or fail using
Jinja2’s defined test. For example:
SIMPLE, POWERFUL BUILTINS
• 261 built-in modules
• Many cloud providers, packages and tools are integrated
• Easily add your own in any language
examples: • ec2 - Create, terminate, start/stop an instance
• docker - Manage docker containers
• hipchat Send a message to hipchat
• s3 - manage objects in S3
• twilio - Sends a text message to a phone
• win_service - Manages Windows services
• zfs - Manage zfs
SMOOTH OPERATION
•Get and set variables easily
•Simple variable precedence
•Ordered, predictable execution
•Tagged, resumable execution
•ansible doc [foo]
SECURITY
• Can be centralized and locked down via Ansible Tower
• Can be run from a centralized bastion server
• Vault encrypts sensitive data
• Uses ordinary SSH, paramiko or custom transport plugins
• No extra open ports, use your own user account, sudo!
• No agents to update or risk vulnerabilities
ADVANCED CAPABILITIES
• Rolling updates/deployment/orchestration (1, 5, n at a time)
• Canary testing (check for page content or response code)
• Variable timeouts and parellelism
• Ansible-pull to invert execution - nodes check in to a master
MORE INFORMATION
https://docs.ansible.com
https://docs.ansible.com/playbooks_best_practices.html
https://galaxy.ansible.com
https://github.com/ansible/ansible-examples
QUESTIONS?
@steveElsewhere
http://linkedin.com/in/devopsto
THANK YOU!
http://devopsdays.org/events/2015-toronto
(shameless plug)
1 von 26

Recomendados

Ansible presentation von
Ansible presentationAnsible presentation
Ansible presentationKumar Y
3.1K views20 Folien
Ansible roles done right von
Ansible roles done rightAnsible roles done right
Ansible roles done rightDan Vaida
1.7K views26 Folien
Ansible intro von
Ansible introAnsible intro
Ansible introMarcelo Quintiliano da Silva
602 views26 Folien
Best practices for ansible von
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
6.8K views95 Folien
Tips for a Faster Website von
Tips for a Faster WebsiteTips for a Faster Website
Tips for a Faster WebsiteRayed Alrashed
987 views43 Folien
Herd your chickens: Ansible for DB2 configuration management von
Herd your chickens: Ansible for DB2 configuration managementHerd your chickens: Ansible for DB2 configuration management
Herd your chickens: Ansible for DB2 configuration managementFrederik Engelen
6.8K views48 Folien

Más contenido relacionado

Was ist angesagt?

Network Automation: Ansible 102 von
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102APNIC
1.6K views66 Folien
Getting started with Ansible von
Getting started with AnsibleGetting started with Ansible
Getting started with AnsibleIvan Serdyuk
498 views83 Folien
Ansible presentation von
Ansible presentationAnsible presentation
Ansible presentationArthur Freyman
720 views54 Folien
Ansible Meetup Hamburg / Quickstart von
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartHenry Stamerjohann
5.2K views44 Folien
Ansible presentation von
Ansible presentationAnsible presentation
Ansible presentationJohn Lynch
34.8K views30 Folien
#OktoCampus - Workshop : An introduction to Ansible von
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
435 views35 Folien

Was ist angesagt?(20)

Network Automation: Ansible 102 von APNIC
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
APNIC1.6K views
Getting started with Ansible von Ivan Serdyuk
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
Ivan Serdyuk498 views
Ansible presentation von John Lynch
Ansible presentationAnsible presentation
Ansible presentation
John Lynch34.8K views
#OktoCampus - Workshop : An introduction to Ansible von Cédric Delgehier
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
Cédric Delgehier435 views
More tips n tricks von bcoca
More tips n tricksMore tips n tricks
More tips n tricks
bcoca5.3K views
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12 von Keith Resar
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
Keith Resar1.2K views
Ansible, best practices von Bas Meijer
Ansible, best practicesAnsible, best practices
Ansible, best practices
Bas Meijer13.1K views
Ansible Automation to Rule Them All von Tim Fairweather
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
Tim Fairweather1.5K views
Ansible is the simplest way to automate. MoldCamp, 2015 von Alex S
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015
Alex S4.4K views
IT Automation with Ansible von Rayed Alrashed
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
Rayed Alrashed15.7K views
Ansible for beginners von Kuo-Le Mei
Ansible for beginnersAnsible for beginners
Ansible for beginners
Kuo-Le Mei4.9K views
Ansible : what's ansible & use case by REX von Saewoong Lee
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
Saewoong Lee179 views
Jenkins and ansible reference von laonap166
Jenkins and ansible referenceJenkins and ansible reference
Jenkins and ansible reference
laonap166668 views
Introduction to Ansible von CoreStack
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
CoreStack722 views
AnsibleFest 2014 - Role Tips and Tricks von jimi-c
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricks
jimi-c12.7K views
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017 von Jumping Bean
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
Jumping Bean595 views
V2 and beyond von jimi-c
V2 and beyondV2 and beyond
V2 and beyond
jimi-c13.9K views

Similar a A tour of Ansible

Ansible with oci von
Ansible with ociAnsible with oci
Ansible with ociDonghuKIM2
968 views42 Folien
Ansible new paradigms for orchestration von
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestrationPaolo Tonin
813 views82 Folien
Ansible presentation von
Ansible presentationAnsible presentation
Ansible presentationSuresh Kumar
7.1K views21 Folien
Automating with Ansible von
Automating with AnsibleAutomating with Ansible
Automating with AnsibleRicardo Schmidt
822 views27 Folien
Ansible von
AnsibleAnsible
AnsibleMichal Haták
442 views23 Folien
Puppet von
PuppetPuppet
PuppetSeenaah Seenaahzadeh
654 views15 Folien

Similar a A tour of Ansible(20)

Ansible with oci von DonghuKIM2
Ansible with ociAnsible with oci
Ansible with oci
DonghuKIM2968 views
Ansible new paradigms for orchestration von Paolo Tonin
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestration
Paolo Tonin813 views
Ansible presentation von Suresh Kumar
Ansible presentationAnsible presentation
Ansible presentation
Suresh Kumar7.1K views
Getting Started with Ansible von ahamilton55
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
ahamilton55528 views
Introduction to Ansible - (dev ops for people who hate devops) von Jude A. Goonawardena
Introduction to Ansible - (dev ops for people who hate devops)Introduction to Ansible - (dev ops for people who hate devops)
Introduction to Ansible - (dev ops for people who hate devops)
Puppet: Eclipsecon ALM 2013 von grim_radical
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
grim_radical1.2K views
Ansible Devops North East - slides von InfinityPP
Ansible Devops North East - slides Ansible Devops North East - slides
Ansible Devops North East - slides
InfinityPP97 views
Ansible: How to Get More Sleep and Require Less Coffee von Sarah Z
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
Sarah Z25.5K views
Go Faster with Ansible (AWS meetup) von Richard Donkin
Go Faster with Ansible (AWS meetup)Go Faster with Ansible (AWS meetup)
Go Faster with Ansible (AWS meetup)
Richard Donkin982 views
Automação do físico ao NetSecDevOps von Raul Leite
Automação do físico ao NetSecDevOpsAutomação do físico ao NetSecDevOps
Automação do físico ao NetSecDevOps
Raul Leite470 views
Go Faster with Ansible (PHP meetup) von Richard Donkin
Go Faster with Ansible (PHP meetup)Go Faster with Ansible (PHP meetup)
Go Faster with Ansible (PHP meetup)
Richard Donkin1.4K views
Getting Started with Ansible - Jake.pdf von ssuserd254491
Getting Started with Ansible - Jake.pdfGetting Started with Ansible - Jake.pdf
Getting Started with Ansible - Jake.pdf
ssuserd2544915 views

Último

MS PowerPoint.pptx von
MS PowerPoint.pptxMS PowerPoint.pptx
MS PowerPoint.pptxLitty Sylus
5 views14 Folien
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... von
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...NimaTorabi2
15 views17 Folien
Advanced API Mocking Techniques von
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking TechniquesDimpy Adhikary
23 views11 Folien
Introduction to Maven von
Introduction to MavenIntroduction to Maven
Introduction to MavenJohn Valentino
6 views10 Folien
Airline Booking Software von
Airline Booking SoftwareAirline Booking Software
Airline Booking SoftwareSharmiMehta
6 views26 Folien
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... von
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...sparkfabrik
8 views46 Folien

Último(20)

Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... von NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi215 views
Airline Booking Software von SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta6 views
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... von sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik8 views
Software evolution understanding: Automatic extraction of software identifier... von Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
AI and Ml presentation .pptx von FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8712 views
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... von Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri890 views
Myths and Facts About Hospice Care: Busting Common Misconceptions von Care Coordinations
Myths and Facts About Hospice Care: Busting Common MisconceptionsMyths and Facts About Hospice Care: Busting Common Misconceptions
Myths and Facts About Hospice Care: Busting Common Misconceptions
Dapr Unleashed: Accelerating Microservice Development von Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski12 views
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... von Lisi Hocke
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Lisi Hocke35 views
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... von TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin96 views

A tour of Ansible

  • 2. Steve Pereira 18 years in IT Startups and Enterprise Love learning about, teaching and talking about: • DevOps • CI/CD • Automation • Scale WHO AM I?
  • 3. ANSIBLE FEATURES • Automation for local and remote system provisioning • Automation for local and remote applications deployment • No agents to install on remote systems • Using existing SSHd on remote systems and native SSH on host • Parallel by default - scale to 6000 targets with single master • Language that approaches plain english
  • 4. ANSIBLE CONVENTIONS Playbooks - contain required tasks to configure systems and deploy Tasks - individual actions to perform on remote or local machines Roles - modular, single-purpose configurations for systems Inventory - files containing address information of target machines Handlers - actions triggered by tasks Templates - customizable files destined for managed machines
  • 5. MINIMUM VIABLE ANSIBLE $ ansible all -i 'localhost,' -c local -m ping localhost | success >> { "changed": false, "ping": "pong" }
  • 6. WHAT ELSE? • ansible webservers -m setup • ansible lb -m copy -a "src=hosts dest=/tmp/hosts” • ansible webservers -m yum -a "name=curl state=installed” • ansible webservers -m service -a "name=nginx state=restarted” • ansible-doc -l
  • 7. PLAYBOOKS--- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted example_playbook.yml
  • 8. PLAYBOOKS--- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted example_playbook.yml
  • 9. PLAYBOOKS--- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted example_playbook.yml
  • 10. PLAYBOOKS--- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted example_playbook.yml
  • 11. PLAYBOOKS--- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted example_playbook.yml
  • 12. PLAYBOOKS--- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted example_playbook.yml
  • 13. PLAYBOOKS--- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted example_playbook.yml
  • 14. ROLES my_role/ README.md (readme) defaults/ (default values) meta/ (role metadata) files/ (binaries) templates/ (file templates) handlers/ (operation handlers) tasks/ (playbook files) vars/ (custom variables) • Easily packaged and shared • Download community roles • Mix and match
  • 15. INVENTORY • Define how ansible will interact with remote hosts • Define logical groups of managed nodes • One file for each environment • Default location : /etc/ansible/hosts • INI format, variable overrides sample_inventory.ini [loadbalancers] 10.20.30.41 10.20.30.42 [webservers] 10.20.30.51 hostname=artemis 10.20.30.52 hostname=apollo
  • 16. TEMPLATES • Use Jinja2 templating and variables to customize • Defaults available when variables not provided (dev default with prod override) etc_logrotate.d.j2 {{ logfile }} { rotate {{ 7 | rotate_max }} {{ daily | frequency }} compress missingok notifempty }
  • 17. IT CAN GET FANCY tasks: - name: install packages in a users virtualenv   shell: su - c {{ item[0] }} '(. ./bin/activate && pip install {{ item[1] }})'   with_nested:       - [ 'jim', 'joe', 'jack' ]       - [ package1==1.1,           package2==1.2,           package3==1.3 ] There are several types of loops: Hashes, Fileglobs, Sequence, Subelements, First match, Command results, Random and more but there’s a builtin pip module, anyways.
  • 18. CONDITIONALS tasks: - command: /bin/false register: result ignore_errors:True - command: /bin/something when: result|failed - command: /bin/something_else when: result|success - command: /bin/still/something_else when: result|skipped The result of a play can depend on the value of a variable, fact (something learned about the remote system), or previous task result.
  • 19. MORE CONDITIONALS! tasks: - shell: echo "I've got '{{ foo }}'" when: foo is defined - fail: msg="This play requires 'bar'" when: bar is not defined - command: echo {{ item }} with_items: [ 0, 2, 4, 6, 8, 10 ] when: item > 5 If a required variable has not been set, you can skip or fail using Jinja2’s defined test. For example:
  • 20. SIMPLE, POWERFUL BUILTINS • 261 built-in modules • Many cloud providers, packages and tools are integrated • Easily add your own in any language examples: • ec2 - Create, terminate, start/stop an instance • docker - Manage docker containers • hipchat Send a message to hipchat • s3 - manage objects in S3 • twilio - Sends a text message to a phone • win_service - Manages Windows services • zfs - Manage zfs
  • 21. SMOOTH OPERATION •Get and set variables easily •Simple variable precedence •Ordered, predictable execution •Tagged, resumable execution •ansible doc [foo]
  • 22. SECURITY • Can be centralized and locked down via Ansible Tower • Can be run from a centralized bastion server • Vault encrypts sensitive data • Uses ordinary SSH, paramiko or custom transport plugins • No extra open ports, use your own user account, sudo! • No agents to update or risk vulnerabilities
  • 23. ADVANCED CAPABILITIES • Rolling updates/deployment/orchestration (1, 5, n at a time) • Canary testing (check for page content or response code) • Variable timeouts and parellelism • Ansible-pull to invert execution - nodes check in to a master