SlideShare a Scribd company logo
Introduction to
Ansible
1
What is Ansible?
It's a simple automation language that can perfectly describe an
IT application infrastructure in Ansible Playbooks.
It's an automation engine that runs Ansible Playbooks.
Ansible is an automation platform:
● Playbooks make up the automation language
● The code base is the automation engine.
● Ansible Tower manages existing automation
Community
THE MOST POPULAR OPEN-SOURCE AUTOMATION COMMUNITY ON
GITHUB
● 33,500+ stars & 11,000+ forks on GitHub
● 3,300+ GitHub Contributors
● Over 3000 modules shipped with Ansible
● New contributors added every day
● 1,500+ users on IRC channel
● Top 10 open source projects in 2017
● World-wide meetups taking place every week
● Ansible Galaxy: over 18,000 subscribers
● 500,000+ downloads a month
● AnsibleFests in Austin, NYC, SF, London
http://ansible.com/community
Why Ansible? What Sets Ansible
Apart?
SIMPLE POWERFUL AGENTLESS
Human readable automation App deployment Agentless architecture
No special coding skills needed Configuration management Uses OpenSSH & WinRM
Tasks executed in order Workflow orchestration No agents to exploit or update
Usable by every team Network automation Get started immediately
Get productive quickly Orchestrate the app lifecycle More efficient & more
secure
WHAT CAN I DO USING ANSIBLE?
Orchestration
Automate the deployment and management of your entire IT footprint.
Do this...
Firewalls
Configuration
Management
Application
Deployment
Provisioning Continuous
Delivery
Security and
Compliance
On
these...
Load Balancers Applications Containers Clouds
Servers Infrastructure Storage And
more...
Network Devices
CLOUD VIRT & CONTAINER WINDOWS NETWORK DEVOPS MONITORING
ANSIBLE AUTOMATES TECHNOLOGIES YOU
USE
Time to automate is measured in minutes
Docker
VMwar
e RHV
OpenStack
OpenShift
+more
ACLs
Files
Package
s IIS
Regedits
Shares
Services
Configs
Users
Domains
+more
Arista
A10
Cumulus
Bigswitch
Cisco
Cumulus
Dell
F5
Juniper
Palo Alto
OpenSwitch
+more
Jira
GitHub
Vagrant
Jenkins
Bamboo
Atlassian
Subversion
Slack
Hipchat
+more
Dynatrace
Airbrake
BigPanda
Datadog
LogicMonitor
Nagios
New Relic
PagerDuty
Sensu
StackDriver
Zabbix
+more
STORAGE
NetApp
Red Hat
Storage
Infinidat
+more
AWS
Azure
Digital Ocean
Google
OpenStack
Rackspace
+more
OPERATING
SYSTEMS
RHEL and
Linux UNIX
Windows
+more
Installing Ansible
# you will need the extras repo configured on RHEL,
# along with the Ansible Engine repository on RHEL 7
$ sudo yum install ansible
# Ansible can be installed via “pip”, the Python
# package manager
$ sudo pip install ansible
# you will need the PPA repo configured on
# Debian or Ubuntu
$ sudo apt-get install ansible
ANSIBLE AUTOMATION ENGINE
CMDB
USERS
INVENTORY
HOSTS
NETWORK
DEVICES
PLUGINS
CLI
MODULES
ANSIBLE
PLAYBOOK
PUBLIC / PRIVATE
CLOUD
PUBLIC / PRIVATE
CLOUD
CMDB
USERS
INVENTORY
HOSTS
NETWORK
DEVICES
PLUGINS
CLI
MODULES
ANSIBLE
PLAYBOOK
PUBLIC / PRIVATE
CLOUD
PUBLIC / PRIVATE
CLOUD
ANSIBLE AUTOMATION ENGINE
PLAYBOOKS ARE WRITTEN IN YAML
Tasks are executed
sequentially
Invoke Ansible modules
CMDB
USERS
INVENTORY
HOSTS
NETWORK
DEVICES
PLUGINS
CLI
ANSIBLE
PLAYBOOK
PUBLIC / PRIVATE
CLOUD
PUBLIC / PRIVATE
CLOUD
If Ansible is an engine the modules are
the tools in the toolkit
ANSIBLE
Python, Powershell, or any language Extend
Ansible simplicity to the entire stack
MODULES
CORE NETWORK COMMUNITY
CMDB
USERS
INVENTORY
HOSTS
NETWORK
DEVICES
CLI
ANSIBLE
PLAYBOOK
PUBLIC / PRIVATE
CLOUD
PUBLIC / PRIVATE
CLOUD
PLUGINS ARE “GEARS IN THE ENGINE”
Code that plugs into the core engine
MODULES PLUGINS
CMDB
USERS
HOSTS
NETWORK
ANSIBLE
PLAYBOOK
PUBLIC / PRIVATE
CLOUD
PUBLIC / PRIVATE
CLOUD
MODULES PLUGINS
INVENTORY
INVENTORY
[web]
ANSIBLE AUTOMATION
EwNeGbIsNeErver1
.example.com
webserver2.example.com
[db]
dbserver1.example.com
CLI
[switches]
leaf01.internal.com
leaf02.internal.com
[firewalls]
checkpoint01.internDaEVlI.
CcESom
[lb]
f5-01.internal.com
ANSIBLE AUTOMATION ENGINE
USERS
NETWORK
DEVICES
PLAYBOOK
INVENTORY
PUBLIC / PRIVATE
CLOUD PUBLIC / PRIVATE
CLOUD
CLOUD
RH OpenStack, RH Satellite, VMWare
AAWS, Rackspace, Google Compute Engine, Azure
CMDB
ServiceNow, Cobbler, BMC,Custom cmdb
CMDB
ANSIBLE AUTOMATION ENGINE
USERS
CLI
PLAYBOOK
INVENTORY
PUBLIC / PRIVATE
CLOUD
PUBLIC / PRIVATE
CLOUD
CMDB
HOSTS
NETWORK
DEVICES
MODULES PLUGINS
AUTOMATE EVERYTHING
ARHEL, Ubuntu, Debian,
Cisco routers, Arista switches, Juniper routers,
Windows hosts, Checkpoint firewalls and more
Modules
Modules are bits of code transferred to the target system and executed to satisfy
the task declaration.
● apt/yum
● copy
● file
● get_url
● git
● ping
● debug
● service
● synchronize
● template
● uri
● user
● wait_for
● assert
1
6
docs.ansible.com
Modules: Run Commands
If Ansible doesn't have a module that suits your needs there are
the “run command” modules:
● command: Takes the command and executes it on the host. The
most secure and predictable.
● shell: Executes through a shell like /bin/sh so you can use pipes
etc. Be careful.
● script: Runs a local script on a remote node after transferring it.
● raw: Executes a command without going through the Ansible
module subsystem.
NOTE: Unlike standard modules, run commands have no concept of
desired state and should only be used as a last resort.
Inventory
Inventory is a collection of hosts (nodes) with associated
data and groupings that Ansible can connect and manage.
● Hosts (nodes)
● Groups
● Inventory-specific data (variables)
● Static or dynamic sources
Static Inventory Example
10.42.0.2
10.42.0.6
10.42.0.7
10.42.0.8
10.42.0.100
host.example.com
Static Inventory Example
[control]
tower ansible_host=10.42.0.2
[web]
node-[1:3] ansible_host=10.42.0.[6:8]
[haproxy]
haproxy ansible_host=10.42.0.100
[all:vars]
ansible_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
Use a single source of truth if you have it -- even if
you have multiple sources, Ansible can unify them.
● Stay in sync automatically
● Reduce human error
INVENTORY
2
1
PUBLIC /
PRIVATE
CLOUD
CMDB
Ad-Hoc Commands
An ad-hoc command is a single Ansible task to perform
quickly, but don’t want to save for later.
Ad-Hoc Commands
# check all my inventory hosts are ready to be
# managed by Ansible
$ ansible all -m ping
# collect and display the discovered facts
# for the localhost
$ ansible localhost -m setup
# run the uptime command on all hosts in the
# web group
$ ansible web -m command -a "uptime"
Sidebar: Discovered Facts
Facts are bits of information derived from examining a host systems
that are stored as variables for later use in a play.
$ ansible localhost -m setup
localhost | success >> {
"ansible_facts": {
"ansible_default_ipv4": {
"address": "192.168.1.37",
"alias": "wlan0",
"gateway": "192.168.1.1",
"interface": "wlan0",
"macaddress": "c4:85:08:3b:a9:16",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "192.168.1.0",
"type": "ether"
},
Variables
Ansible can work with metadata from various sources and
manage their context in the form of variables.
● Command line parameters
● Plays and tasks
● Files
● Inventory
● Discovered facts
● Roles
Variable Precedence
The order in which the same variable from different sources will
override each other.
● extra vars
● task vars (only for the task)
● block vars (only for tasks in
block)
● role and include vars
● play vars_files
● play vars_prompt
● play vars
● set_facts
● registered vars
● host facts
● playbook host_vars
● playbook group_vars
● Inventory host_vars
● inventory group_vars
● inventory vars
● role defaults
Tasks
Tasks are the application of a module to perform a specific unit of
work.
● file: A directory should exist
● yum: A package should be installed
● service: A service should be running
● template: Render a configuration file from a template
● get_url: Fetch an archive file from a URL
● git: Clone a source code repository
Example Tasks in a Play
tasks:
- name: httpd package is present
yum:
name: httpd
state: latest
- name: latest index.html file is present
copy:
src: files/index.html
dest: /var/www/html/
- name: restart httpd
service:
name: httpd
state: restarted
Handler Tasks
Handlers are special tasks that run at the end of a play if
notified by another task when a change occurs.
If a package gets installed or updated, notify a service restart task
that it needs to run.
Example Handler Task in a Play
tasks:
- name: httpd package is present
yum:
name: httpd
state: latest
notify: restart httpd
- name: latest index.html file is present
copy:
src: files/index.html
dest: /var/www/html/
handlers:
- name: restart httpd
service:
name: httpd
state: restarted
Plays & Playbooks
Plays are ordered sets of tasks to execute against host
selections from your inventory. A playbook is a file containing
one or more plays.
Playbook Example
---
- name: install and start apache
hosts: web
become: yes
vars:
http_port: 80
tasks:
- name: httpd package is present
yum:
name: httpd
state: latest
- name: latest index.html file is present
copy:
src: files/index.html
dest:/var/www/html/
- name: start httpd
service:
name: httpd
state: started
Human-Meaningful Naming
---
- name: install and start apache
hosts: web
become: yes
vars:
http_port: 80
tasks:
- name: httpd package is present
yum:
name: httpd
state: latest
- name: latest index.html file is present
copy:
src: files/index.html
dest: /var/www/html/
- name: httpd is started
service:
name: httpd
state: started
Host Selector
---
- name: install and start apache
hosts: web
become: yes
vars:
http_port: 80
tasks:
- name: httpd package is present
yum:
name: httpd
state: latest
- name: latest index.html file is present
copy:
src: files/index.html
dest: /var/www/html/
- name: httpd is started
service:
name: httpd
state: started
Privilege Escalation
---
- name: install and start apache
hosts: web
become: yes
vars:
http_port: 80
tasks:
- name: httpd package is present
yum:
name: httpd
state: latest
- name: latest index.html file is present
copy:
src: files/index.html
dest: /var/www/html/
- name: httpd is started
service:
name: httpd
state: started
Play Variables
---
- name: install and start apache
hosts: web
become: yes
vars:
http_port: 80
tasks:
- name: httpd package is present
yum:
name: httpd
state: latest
- name: latest index.html file is present
copy:
src: files/index.html
dest: /var/www/html/
- name: httpd is started
service:
name: httpd
state: started
Tasks
---
- name: install and start apache
hosts: web
become: yes
vars:
http_port: 80
tasks:
- name: httpd package is present
yum:
name: httpd
state: latest
- name: latest index.html file is present
copy:
src: files/index.html
dest: /var/www/html/
- name: httpd is started
service:
name: httpd
state: started
Role
s
Roles are a packages of closely related Ansible content that
can be shared more easily than plays alone.
● Improves readability and maintainability of complex plays
● Eases sharing, reuse and standardization of automation
processes
● Enables Ansible content to exist independently of
playbooks, projects -- even organizations
● Provides functional conveniences such as file path
resolution and default values
Project with Embedded Roles Example
site.yml
roles/
common/
files/
templates/
tasks/
handlers/
vars/
defaults/
meta/
apache/
files/
templates/
tasks/
handlers/
vars/
defaults/
meta/
Project with Embedded Roles Example
# site.yml
---
- hosts: web
roles:
- common
- apache
Q&A
Thank
You!

More Related Content

PDF
Ansible 2.0 - How to use Ansible to automate your applications in AWS.
PDF
Ansible
PDF
How Ansible Makes Automation Easy
PDF
Introduction to Ansible (Pycon7 2016)
PDF
Ansible is the simplest way to automate. SymfonyCafe, 2015
PPTX
Monitor-Driven Development Using Ansible
PDF
Deploying PHP Applications with Ansible
PPTX
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Ansible 2.0 - How to use Ansible to automate your applications in AWS.
Ansible
How Ansible Makes Automation Easy
Introduction to Ansible (Pycon7 2016)
Ansible is the simplest way to automate. SymfonyCafe, 2015
Monitor-Driven Development Using Ansible
Deploying PHP Applications with Ansible
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec

What's hot (20)

PDF
Take control of your Jenkins jobs via job DSL.
PPTX
Ansible module development 101
PDF
Investigation of testing with ansible
PDF
Ansible not only for Dummies
PDF
Continuous Integration: SaaS vs Jenkins in Cloud
PDF
Ansible Crash Course
PDF
Ansible - A 'crowd' introduction
PPTX
DevOps, A brief introduction to Vagrant & Ansible
PDF
Ansible - Hands on Training
PPTX
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
PDF
Testing Ansible with Jenkins and Docker
PDF
Getting started with Ansible
PDF
Ansible Automation to Rule Them All
PPTX
Docker ansible-make-chef-puppet-unnecessary-minnihan
PDF
Introduction to ansible galaxy
PDF
Fluentd Meetup 2016 - ServerEngine Integration & Windows support
PDF
DevOps for Humans - Ansible for Drupal Deployment Victory!
PDF
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
PDF
Continuous infrastructure testing
PPTX
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Take control of your Jenkins jobs via job DSL.
Ansible module development 101
Investigation of testing with ansible
Ansible not only for Dummies
Continuous Integration: SaaS vs Jenkins in Cloud
Ansible Crash Course
Ansible - A 'crowd' introduction
DevOps, A brief introduction to Vagrant & Ansible
Ansible - Hands on Training
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
Testing Ansible with Jenkins and Docker
Getting started with Ansible
Ansible Automation to Rule Them All
Docker ansible-make-chef-puppet-unnecessary-minnihan
Introduction to ansible galaxy
Fluentd Meetup 2016 - ServerEngine Integration & Windows support
DevOps for Humans - Ansible for Drupal Deployment Victory!
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Continuous infrastructure testing
Ansible Automation Best Practices From Startups to Enterprises - Minnebar 12
Ad

Similar to Intro to-ansible-sep7-meetup (20)

PPTX
Ansible as configuration management tool for devops
PPTX
Introduction to ansible
PDF
Getting Started with Ansible - Jake.pdf
PDF
ansible_rhel.pdf
PDF
Ansible automation sa technical deck q2 fy19
PPTX
SESSION Ansible how to deploy and push resources
PPTX
Introduction to Ansible - (dev ops for people who hate devops)
PDF
Automating with ansible (part a)
PDF
Introduction to Ansible in RHEL- RHCE.pdf
PPTX
Automating with ansible (Part A)
PPTX
Ansible
PDF
#OktoCampus - Workshop : An introduction to Ansible
PDF
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
PDF
Top 50 Ansible Interview Questions And Answers in 2023.pdf
PDF
Ansible Tutorial.pdf
PDF
Automate with Ansible basic (2/e, English)
PPTX
Ansible: What, Why & How
PDF
A quick intro to Ansible
PDF
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Ansible as configuration management tool for devops
Introduction to ansible
Getting Started with Ansible - Jake.pdf
ansible_rhel.pdf
Ansible automation sa technical deck q2 fy19
SESSION Ansible how to deploy and push resources
Introduction to Ansible - (dev ops for people who hate devops)
Automating with ansible (part a)
Introduction to Ansible in RHEL- RHCE.pdf
Automating with ansible (Part A)
Ansible
#OktoCampus - Workshop : An introduction to Ansible
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
Top 50 Ansible Interview Questions And Answers in 2023.pdf
Ansible Tutorial.pdf
Automate with Ansible basic (2/e, English)
Ansible: What, Why & How
A quick intro to Ansible
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Ad

Recently uploaded (20)

DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
PPT on Performance Review to get promotions
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Geodesy 1.pptx...............................................
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
additive manufacturing of ss316l using mig welding
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPT on Performance Review to get promotions
Foundation to blockchain - A guide to Blockchain Tech
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Lesson 3_Tessellation.pptx finite Mathematics
Geodesy 1.pptx...............................................
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
additive manufacturing of ss316l using mig welding
bas. eng. economics group 4 presentation 1.pptx
UNIT 4 Total Quality Management .pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx

Intro to-ansible-sep7-meetup

  • 2. What is Ansible? It's a simple automation language that can perfectly describe an IT application infrastructure in Ansible Playbooks. It's an automation engine that runs Ansible Playbooks. Ansible is an automation platform: ● Playbooks make up the automation language ● The code base is the automation engine. ● Ansible Tower manages existing automation
  • 3. Community THE MOST POPULAR OPEN-SOURCE AUTOMATION COMMUNITY ON GITHUB ● 33,500+ stars & 11,000+ forks on GitHub ● 3,300+ GitHub Contributors ● Over 3000 modules shipped with Ansible ● New contributors added every day ● 1,500+ users on IRC channel ● Top 10 open source projects in 2017 ● World-wide meetups taking place every week ● Ansible Galaxy: over 18,000 subscribers ● 500,000+ downloads a month ● AnsibleFests in Austin, NYC, SF, London http://ansible.com/community
  • 4. Why Ansible? What Sets Ansible Apart? SIMPLE POWERFUL AGENTLESS Human readable automation App deployment Agentless architecture No special coding skills needed Configuration management Uses OpenSSH & WinRM Tasks executed in order Workflow orchestration No agents to exploit or update Usable by every team Network automation Get started immediately Get productive quickly Orchestrate the app lifecycle More efficient & more secure
  • 5. WHAT CAN I DO USING ANSIBLE? Orchestration Automate the deployment and management of your entire IT footprint. Do this... Firewalls Configuration Management Application Deployment Provisioning Continuous Delivery Security and Compliance On these... Load Balancers Applications Containers Clouds Servers Infrastructure Storage And more... Network Devices
  • 6. CLOUD VIRT & CONTAINER WINDOWS NETWORK DEVOPS MONITORING ANSIBLE AUTOMATES TECHNOLOGIES YOU USE Time to automate is measured in minutes Docker VMwar e RHV OpenStack OpenShift +more ACLs Files Package s IIS Regedits Shares Services Configs Users Domains +more Arista A10 Cumulus Bigswitch Cisco Cumulus Dell F5 Juniper Palo Alto OpenSwitch +more Jira GitHub Vagrant Jenkins Bamboo Atlassian Subversion Slack Hipchat +more Dynatrace Airbrake BigPanda Datadog LogicMonitor Nagios New Relic PagerDuty Sensu StackDriver Zabbix +more STORAGE NetApp Red Hat Storage Infinidat +more AWS Azure Digital Ocean Google OpenStack Rackspace +more OPERATING SYSTEMS RHEL and Linux UNIX Windows +more
  • 7. Installing Ansible # you will need the extras repo configured on RHEL, # along with the Ansible Engine repository on RHEL 7 $ sudo yum install ansible # Ansible can be installed via “pip”, the Python # package manager $ sudo pip install ansible # you will need the PPA repo configured on # Debian or Ubuntu $ sudo apt-get install ansible
  • 9. CMDB USERS INVENTORY HOSTS NETWORK DEVICES PLUGINS CLI MODULES ANSIBLE PLAYBOOK PUBLIC / PRIVATE CLOUD PUBLIC / PRIVATE CLOUD ANSIBLE AUTOMATION ENGINE PLAYBOOKS ARE WRITTEN IN YAML Tasks are executed sequentially Invoke Ansible modules
  • 10. CMDB USERS INVENTORY HOSTS NETWORK DEVICES PLUGINS CLI ANSIBLE PLAYBOOK PUBLIC / PRIVATE CLOUD PUBLIC / PRIVATE CLOUD If Ansible is an engine the modules are the tools in the toolkit ANSIBLE Python, Powershell, or any language Extend Ansible simplicity to the entire stack MODULES CORE NETWORK COMMUNITY
  • 11. CMDB USERS INVENTORY HOSTS NETWORK DEVICES CLI ANSIBLE PLAYBOOK PUBLIC / PRIVATE CLOUD PUBLIC / PRIVATE CLOUD PLUGINS ARE “GEARS IN THE ENGINE” Code that plugs into the core engine MODULES PLUGINS
  • 12. CMDB USERS HOSTS NETWORK ANSIBLE PLAYBOOK PUBLIC / PRIVATE CLOUD PUBLIC / PRIVATE CLOUD MODULES PLUGINS INVENTORY INVENTORY [web] ANSIBLE AUTOMATION EwNeGbIsNeErver1 .example.com webserver2.example.com [db] dbserver1.example.com CLI [switches] leaf01.internal.com leaf02.internal.com [firewalls] checkpoint01.internDaEVlI. CcESom [lb] f5-01.internal.com
  • 13. ANSIBLE AUTOMATION ENGINE USERS NETWORK DEVICES PLAYBOOK INVENTORY PUBLIC / PRIVATE CLOUD PUBLIC / PRIVATE CLOUD CLOUD RH OpenStack, RH Satellite, VMWare AAWS, Rackspace, Google Compute Engine, Azure CMDB ServiceNow, Cobbler, BMC,Custom cmdb CMDB
  • 14. ANSIBLE AUTOMATION ENGINE USERS CLI PLAYBOOK INVENTORY PUBLIC / PRIVATE CLOUD PUBLIC / PRIVATE CLOUD CMDB HOSTS NETWORK DEVICES MODULES PLUGINS AUTOMATE EVERYTHING ARHEL, Ubuntu, Debian, Cisco routers, Arista switches, Juniper routers, Windows hosts, Checkpoint firewalls and more
  • 15. Modules Modules are bits of code transferred to the target system and executed to satisfy the task declaration. ● apt/yum ● copy ● file ● get_url ● git ● ping ● debug ● service ● synchronize ● template ● uri ● user ● wait_for ● assert
  • 17. Modules: Run Commands If Ansible doesn't have a module that suits your needs there are the “run command” modules: ● command: Takes the command and executes it on the host. The most secure and predictable. ● shell: Executes through a shell like /bin/sh so you can use pipes etc. Be careful. ● script: Runs a local script on a remote node after transferring it. ● raw: Executes a command without going through the Ansible module subsystem. NOTE: Unlike standard modules, run commands have no concept of desired state and should only be used as a last resort.
  • 18. Inventory Inventory is a collection of hosts (nodes) with associated data and groupings that Ansible can connect and manage. ● Hosts (nodes) ● Groups ● Inventory-specific data (variables) ● Static or dynamic sources
  • 20. Static Inventory Example [control] tower ansible_host=10.42.0.2 [web] node-[1:3] ansible_host=10.42.0.[6:8] [haproxy] haproxy ansible_host=10.42.0.100 [all:vars] ansible_user=vagrant ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
  • 21. Use a single source of truth if you have it -- even if you have multiple sources, Ansible can unify them. ● Stay in sync automatically ● Reduce human error INVENTORY 2 1 PUBLIC / PRIVATE CLOUD CMDB
  • 22. Ad-Hoc Commands An ad-hoc command is a single Ansible task to perform quickly, but don’t want to save for later.
  • 23. Ad-Hoc Commands # check all my inventory hosts are ready to be # managed by Ansible $ ansible all -m ping # collect and display the discovered facts # for the localhost $ ansible localhost -m setup # run the uptime command on all hosts in the # web group $ ansible web -m command -a "uptime"
  • 24. Sidebar: Discovered Facts Facts are bits of information derived from examining a host systems that are stored as variables for later use in a play. $ ansible localhost -m setup localhost | success >> { "ansible_facts": { "ansible_default_ipv4": { "address": "192.168.1.37", "alias": "wlan0", "gateway": "192.168.1.1", "interface": "wlan0", "macaddress": "c4:85:08:3b:a9:16", "mtu": 1500, "netmask": "255.255.255.0", "network": "192.168.1.0", "type": "ether" },
  • 25. Variables Ansible can work with metadata from various sources and manage their context in the form of variables. ● Command line parameters ● Plays and tasks ● Files ● Inventory ● Discovered facts ● Roles
  • 26. Variable Precedence The order in which the same variable from different sources will override each other. ● extra vars ● task vars (only for the task) ● block vars (only for tasks in block) ● role and include vars ● play vars_files ● play vars_prompt ● play vars ● set_facts ● registered vars ● host facts ● playbook host_vars ● playbook group_vars ● Inventory host_vars ● inventory group_vars ● inventory vars ● role defaults
  • 27. Tasks Tasks are the application of a module to perform a specific unit of work. ● file: A directory should exist ● yum: A package should be installed ● service: A service should be running ● template: Render a configuration file from a template ● get_url: Fetch an archive file from a URL ● git: Clone a source code repository
  • 28. Example Tasks in a Play tasks: - name: httpd package is present yum: name: httpd state: latest - name: latest index.html file is present copy: src: files/index.html dest: /var/www/html/ - name: restart httpd service: name: httpd state: restarted
  • 29. Handler Tasks Handlers are special tasks that run at the end of a play if notified by another task when a change occurs. If a package gets installed or updated, notify a service restart task that it needs to run.
  • 30. Example Handler Task in a Play tasks: - name: httpd package is present yum: name: httpd state: latest notify: restart httpd - name: latest index.html file is present copy: src: files/index.html dest: /var/www/html/ handlers: - name: restart httpd service: name: httpd state: restarted
  • 31. Plays & Playbooks Plays are ordered sets of tasks to execute against host selections from your inventory. A playbook is a file containing one or more plays.
  • 32. Playbook Example --- - name: install and start apache hosts: web become: yes vars: http_port: 80 tasks: - name: httpd package is present yum: name: httpd state: latest - name: latest index.html file is present copy: src: files/index.html dest:/var/www/html/ - name: start httpd service: name: httpd state: started
  • 33. Human-Meaningful Naming --- - name: install and start apache hosts: web become: yes vars: http_port: 80 tasks: - name: httpd package is present yum: name: httpd state: latest - name: latest index.html file is present copy: src: files/index.html dest: /var/www/html/ - name: httpd is started service: name: httpd state: started
  • 34. Host Selector --- - name: install and start apache hosts: web become: yes vars: http_port: 80 tasks: - name: httpd package is present yum: name: httpd state: latest - name: latest index.html file is present copy: src: files/index.html dest: /var/www/html/ - name: httpd is started service: name: httpd state: started
  • 35. Privilege Escalation --- - name: install and start apache hosts: web become: yes vars: http_port: 80 tasks: - name: httpd package is present yum: name: httpd state: latest - name: latest index.html file is present copy: src: files/index.html dest: /var/www/html/ - name: httpd is started service: name: httpd state: started
  • 36. Play Variables --- - name: install and start apache hosts: web become: yes vars: http_port: 80 tasks: - name: httpd package is present yum: name: httpd state: latest - name: latest index.html file is present copy: src: files/index.html dest: /var/www/html/ - name: httpd is started service: name: httpd state: started
  • 37. Tasks --- - name: install and start apache hosts: web become: yes vars: http_port: 80 tasks: - name: httpd package is present yum: name: httpd state: latest - name: latest index.html file is present copy: src: files/index.html dest: /var/www/html/ - name: httpd is started service: name: httpd state: started
  • 38. Role s Roles are a packages of closely related Ansible content that can be shared more easily than plays alone. ● Improves readability and maintainability of complex plays ● Eases sharing, reuse and standardization of automation processes ● Enables Ansible content to exist independently of playbooks, projects -- even organizations ● Provides functional conveniences such as file path resolution and default values
  • 39. Project with Embedded Roles Example site.yml roles/ common/ files/ templates/ tasks/ handlers/ vars/ defaults/ meta/ apache/ files/ templates/ tasks/ handlers/ vars/ defaults/ meta/
  • 40. Project with Embedded Roles Example # site.yml --- - hosts: web roles: - common - apache
  • 41. Q&A