SlideShare a Scribd company logo
Introduction to Ansible
Peter Halligan
Introduction
Introduction
Ansible is an python based tool for deployment and orchestration of
infrastructure
It is agentless and communicates with hosts via ssh
Push based
Easy to read
overview
Installation
● Pre-installed on many linux distro
● Use package manager
● Use pip install
● MacOs pip install
○ CC=clang sudo -E pip install pycrypto.
● Not officially supported on windows
○ Cygwin
○ Linux subsytem.
We can still manage
windows hosts even if
Ansible does not support
windows as a management
machine
Components
- Playbooks
- Tasks
- Inventory files
- Variables
- Filters
- Roles
- Ansible tower
- awx
Suggested directory structure
Playbooks, plays & tasks
Playbook and Plays
Playbooks are made up of one or more
plays.
Indentation is important!!!
A play is a set of task which are run on
the host pattern outlined by the play.
Common keywords used to control the
play
Tasks
Tasks are a list of modules to be
executed in order.
Modules are written to be idempotent.
Which means they can be run multiple
times and result will be the same each
time.
Script, command, shell commands
may not return the same result each
time.
Pre-tasks, post-tasks, blocks
Inventory
Static Inventory
Static defined by user
Organised into groups
All hosts belong to at least 2 groups
Can use patterns to decide what hosts
to run plays on, including multiple
groups, excluding groups or an
intersection of groups
We can also store variable data in
inventory files
Dynamic Inventory
Python scripts and modules which can
generate the inventory file
Must enable the plugin
Can organise based on tags
Difficult set up for gce
Plugin not working properly on ansible
2.6 or 2.7
Variables
Variables
Currently there are over 20 places we
can define a variable.
Tasks in a role will see their own
default vars
Tasks defined outside a role will see
the last roles role defaults
If multiple groups have the same
named variable the last to load will be
used.
Hosts at the same group level load
alphabetically
● command line values (eg “-u user”)
● role defaults
● inventory file or script group vars
● inventory group_vars/all
● playbook group_vars/all
● inventory group_vars/*
● playbook group_vars/*
● inventory file or script host vars
● inventory host_vars/*
● playbook host_vars/*
● host facts / cached set_facts
● play vars
● play vars_prompt
● play vars_files
● role vars (defined in role/vars/main.yml)
● block vars (only for tasks in block)
● task vars (only for the task)
● include_vars
● set_facts / registered vars
● role (and include_role) params
● include params
● extra vars (always win precedence) -e “this=that”
https://docs.ansible.com/ansible/2.7/user_guide/playbooks_variables.html#variabl
e-precedence-where-should-i-put-a-variable
Variables
When a play is run generally the setup
module is run. We can disable it using
gather_facts: false.
Gather facts gives us access to a lot
of vars on the target machine. Too
many to list here. (ansible all -m setup)
Arguments can be accessed with
bracket or dot notation
Registered vars are where we save the
output from a task
ansible hostname -m setup
- debug: var=ansible_facts
{{ ansible_facts['devices']['xvda']['model'] }}
//can cause conflicts with python
{{ ansible_facts.devices.xvda.model }}
- hosts: web_servers
tasks:
- shell: /usr/bin/foo
register: foo_result
ignore_errors: True
- shell: /usr/bin/bar
when: foo_result.rc == 5
Templates
Templates use the jinja2 templating
engine
The modules takes a source template
which contains a placeholder for a var:
{{ my_var }} replaces it on the
controller machine with the var and
then copies it to the destination host
Roles
Roles
Roles are a way to organise and reuse
and share ansible content; tasks, file
vars, templates etc
Similar to the default structure
ansible -galaxy contains many roles
Import (static) v include (dynamic)
Previously had to use roles, pre-task,
post-tasks more difficult to control the
flow of tasks
Rolling updates
Rolling updates
Rolling updates are simple
Add the serial keyword to the play
Add max_fail_percentage (optional)
Run your playbook
Example can pass a list of numbers or
percentage to a serial and it will run
first on 1 host, then on 5, then on 20%
of remaining machines until
completion
Setting max_fail_percentage: would
act on all those groups too
Other Topics
ansible-galaxy
filters
plugins
Configuration options
Resources
https://docs.ansible.com/
https://www.ansiblefordevops.com/
https://www.safaribooksonline.com/videos/hands-on-infrastructure-automation/9781788991599
Configuration Management 101: Writing Ansible Playbooks
https://www.safaribooksonline.com/library/view/learn-ansible/9781788998758/
Thanks!
Contact:
Peter Halligan
peter.halligan@mycit.ie
https://www.linkedin.com/in/hall
iganpeter/

More Related Content

PPTX
Ansible 101, Gennadiy Mykhailiuta
PPTX
Using Ansible Dynamic Inventory with Amazon EC2
PDF
Development of Ansible modules
PDF
Configuration Management in Ansible
PDF
Using Ansible for Deploying to Cloud Environments
PDF
Ansible roles done right
PDF
Ansible Meetup Hamburg / Quickstart
PDF
Ansible leveraging 2.0
Ansible 101, Gennadiy Mykhailiuta
Using Ansible Dynamic Inventory with Amazon EC2
Development of Ansible modules
Configuration Management in Ansible
Using Ansible for Deploying to Cloud Environments
Ansible roles done right
Ansible Meetup Hamburg / Quickstart
Ansible leveraging 2.0

What's hot (20)

PDF
Bangpypers april-meetup-2012
PDF
Automating with ansible (part a)
PPTX
Ansible fest Presentation slides
PDF
Ansible Introduction - Ansible Brno #1 - David Karban
PDF
Ansible is the simplest way to automate. MoldCamp, 2015
PDF
Automation and Ansible
PDF
Network Automation: Ansible 102
PPTX
Ansible presentation
PDF
Virtualize and automate your development environment for fun and profit
PPTX
DevOps with Fabric
PDF
Writing and Publishing Puppet Modules
PDF
Automating with ansible (Part c)
ODP
ansible why ?
PDF
Puppet @ Seat
PDF
Custom Non-RDS Multi-AZ Mysql Replication
PDF
Puppi. Puppet strings to the shell
PDF
Artem Yavorsky "99 ways to take away your ugly polyfills"
PDF
Ansible loves Python, Python Philadelphia meetup
PDF
Puppet Camp Ghent 2013
Bangpypers april-meetup-2012
Automating with ansible (part a)
Ansible fest Presentation slides
Ansible Introduction - Ansible Brno #1 - David Karban
Ansible is the simplest way to automate. MoldCamp, 2015
Automation and Ansible
Network Automation: Ansible 102
Ansible presentation
Virtualize and automate your development environment for fun and profit
DevOps with Fabric
Writing and Publishing Puppet Modules
Automating with ansible (Part c)
ansible why ?
Puppet @ Seat
Custom Non-RDS Multi-AZ Mysql Replication
Puppi. Puppet strings to the shell
Artem Yavorsky "99 ways to take away your ugly polyfills"
Ansible loves Python, Python Philadelphia meetup
Puppet Camp Ghent 2013
Ad

Similar to Introduction to Ansible - Peter Halligan (20)

PDF
Jenkins and ansible reference
PPTX
SESSION Ansible how to deploy and push resources
PDF
Configuration management I - Ansible + Packer
PDF
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
PDF
Ansible
PDF
Introduction to Ansible in RHEL- RHCE.pdf
PPTX
Ansible as configuration management tool for devops
PDF
Ansible Variables in Playbook - RHCE.pdf
PPTX
Introduction to Ansible
PPTX
Introduction to ansible
PDF
Ansible a tool for dev ops
PDF
Getting Started with Ansible
PDF
Ansible_Basics_ppt.pdf
PPTX
ansible : Infrastructure automation,idempotent and more
PDF
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
PDF
Network Automation: Ansible 101
PPTX
Introduction to Ansible - Jan 28 - Austin MeetUp
PDF
Ansible Overview - System Administration and Maintenance
PPTX
Intro to-ansible-sep7-meetup
Jenkins and ansible reference
SESSION Ansible how to deploy and push resources
Configuration management I - Ansible + Packer
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible
Introduction to Ansible in RHEL- RHCE.pdf
Ansible as configuration management tool for devops
Ansible Variables in Playbook - RHCE.pdf
Introduction to Ansible
Introduction to ansible
Ansible a tool for dev ops
Getting Started with Ansible
Ansible_Basics_ppt.pdf
ansible : Infrastructure automation,idempotent and more
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Network Automation: Ansible 101
Introduction to Ansible - Jan 28 - Austin MeetUp
Ansible Overview - System Administration and Maintenance
Intro to-ansible-sep7-meetup
Ad

Recently uploaded (20)

PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
STKI Israel Market Study 2025 version august
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Getting Started with Data Integration: FME Form 101
PDF
project resource management chapter-09.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Hybrid model detection and classification of lung cancer
PDF
Getting started with AI Agents and Multi-Agent Systems
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
The various Industrial Revolutions .pptx
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
Modernising the Digital Integration Hub
OMC Textile Division Presentation 2021.pptx
Hindi spoken digit analysis for native and non-native speakers
Final SEM Unit 1 for mit wpu at pune .pptx
A contest of sentiment analysis: k-nearest neighbor versus neural network
1 - Historical Antecedents, Social Consideration.pdf
STKI Israel Market Study 2025 version august
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Getting Started with Data Integration: FME Form 101
project resource management chapter-09.pdf
Group 1 Presentation -Planning and Decision Making .pptx
WOOl fibre morphology and structure.pdf for textiles
Hybrid model detection and classification of lung cancer
Getting started with AI Agents and Multi-Agent Systems
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles – August ’25 Week III
The various Industrial Revolutions .pptx
Web App vs Mobile App What Should You Build First.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Enhancing emotion recognition model for a student engagement use case through...
Modernising the Digital Integration Hub

Introduction to Ansible - Peter Halligan

  • 3. Introduction Ansible is an python based tool for deployment and orchestration of infrastructure It is agentless and communicates with hosts via ssh Push based Easy to read
  • 5. Installation ● Pre-installed on many linux distro ● Use package manager ● Use pip install ● MacOs pip install ○ CC=clang sudo -E pip install pycrypto. ● Not officially supported on windows ○ Cygwin ○ Linux subsytem. We can still manage windows hosts even if Ansible does not support windows as a management machine
  • 6. Components - Playbooks - Tasks - Inventory files - Variables - Filters - Roles - Ansible tower - awx Suggested directory structure
  • 8. Playbook and Plays Playbooks are made up of one or more plays. Indentation is important!!! A play is a set of task which are run on the host pattern outlined by the play. Common keywords used to control the play
  • 9. Tasks Tasks are a list of modules to be executed in order. Modules are written to be idempotent. Which means they can be run multiple times and result will be the same each time. Script, command, shell commands may not return the same result each time. Pre-tasks, post-tasks, blocks
  • 11. Static Inventory Static defined by user Organised into groups All hosts belong to at least 2 groups Can use patterns to decide what hosts to run plays on, including multiple groups, excluding groups or an intersection of groups We can also store variable data in inventory files
  • 12. Dynamic Inventory Python scripts and modules which can generate the inventory file Must enable the plugin Can organise based on tags Difficult set up for gce Plugin not working properly on ansible 2.6 or 2.7
  • 14. Variables Currently there are over 20 places we can define a variable. Tasks in a role will see their own default vars Tasks defined outside a role will see the last roles role defaults If multiple groups have the same named variable the last to load will be used. Hosts at the same group level load alphabetically ● command line values (eg “-u user”) ● role defaults ● inventory file or script group vars ● inventory group_vars/all ● playbook group_vars/all ● inventory group_vars/* ● playbook group_vars/* ● inventory file or script host vars ● inventory host_vars/* ● playbook host_vars/* ● host facts / cached set_facts ● play vars ● play vars_prompt ● play vars_files ● role vars (defined in role/vars/main.yml) ● block vars (only for tasks in block) ● task vars (only for the task) ● include_vars ● set_facts / registered vars ● role (and include_role) params ● include params ● extra vars (always win precedence) -e “this=that” https://docs.ansible.com/ansible/2.7/user_guide/playbooks_variables.html#variabl e-precedence-where-should-i-put-a-variable
  • 15. Variables When a play is run generally the setup module is run. We can disable it using gather_facts: false. Gather facts gives us access to a lot of vars on the target machine. Too many to list here. (ansible all -m setup) Arguments can be accessed with bracket or dot notation Registered vars are where we save the output from a task ansible hostname -m setup - debug: var=ansible_facts {{ ansible_facts['devices']['xvda']['model'] }} //can cause conflicts with python {{ ansible_facts.devices.xvda.model }} - hosts: web_servers tasks: - shell: /usr/bin/foo register: foo_result ignore_errors: True - shell: /usr/bin/bar when: foo_result.rc == 5
  • 16. Templates Templates use the jinja2 templating engine The modules takes a source template which contains a placeholder for a var: {{ my_var }} replaces it on the controller machine with the var and then copies it to the destination host
  • 17. Roles
  • 18. Roles Roles are a way to organise and reuse and share ansible content; tasks, file vars, templates etc Similar to the default structure ansible -galaxy contains many roles Import (static) v include (dynamic) Previously had to use roles, pre-task, post-tasks more difficult to control the flow of tasks
  • 20. Rolling updates Rolling updates are simple Add the serial keyword to the play Add max_fail_percentage (optional) Run your playbook Example can pass a list of numbers or percentage to a serial and it will run first on 1 host, then on 5, then on 20% of remaining machines until completion Setting max_fail_percentage: would act on all those groups too