SlideShare ist ein Scribd-Unternehmen logo
1 von 23
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/

Weitere ähnliche Inhalte

Was ist angesagt?

Virtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profitVirtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profit
Andreas Heim
 

Was ist angesagt? (20)

Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Automating with ansible (part a)
Automating with ansible (part a)Automating with ansible (part a)
Automating with ansible (part a)
 
Ansible fest Presentation slides
Ansible fest Presentation slidesAnsible fest Presentation slides
Ansible fest Presentation slides
 
Ansible Introduction - Ansible Brno #1 - David Karban
Ansible Introduction - Ansible Brno #1 - David KarbanAnsible Introduction - Ansible Brno #1 - David Karban
Ansible Introduction - Ansible Brno #1 - David Karban
 
Ansible is the simplest way to automate. MoldCamp, 2015
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
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansible
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Puppet
PuppetPuppet
Puppet
 
Virtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profitVirtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profit
 
DevOps with Fabric
DevOps with FabricDevOps with Fabric
DevOps with Fabric
 
Writing and Publishing Puppet Modules
Writing and Publishing Puppet ModulesWriting and Publishing Puppet Modules
Writing and Publishing Puppet Modules
 
Automating with ansible (Part c)
Automating with ansible (Part c) Automating with ansible (Part c)
Automating with ansible (Part c)
 
ansible why ?
ansible why ?ansible why ?
ansible why ?
 
Puppet @ Seat
Puppet @ SeatPuppet @ Seat
Puppet @ Seat
 
Custom Non-RDS Multi-AZ Mysql Replication
Custom Non-RDS Multi-AZ Mysql ReplicationCustom Non-RDS Multi-AZ Mysql Replication
Custom Non-RDS Multi-AZ Mysql Replication
 
Puppi. Puppet strings to the shell
Puppi. Puppet strings to the shellPuppi. Puppet strings to the shell
Puppi. Puppet strings to the shell
 
Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"
 
Ansible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetupAnsible loves Python, Python Philadelphia meetup
Ansible loves Python, Python Philadelphia meetup
 
Puppet Camp Ghent 2013
Puppet Camp Ghent 2013Puppet Camp Ghent 2013
Puppet Camp Ghent 2013
 

Ähnlich wie Introduction to Ansible - Peter Halligan

Ähnlich wie Introduction to Ansible - Peter Halligan (20)

Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Ansible intro
Ansible introAnsible intro
Ansible intro
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 
Ansible is Our Wishbone(Automate DBA Tasks With Ansible)
Ansible is Our Wishbone(Automate DBA Tasks With Ansible)Ansible is Our Wishbone(Automate DBA Tasks With Ansible)
Ansible is Our Wishbone(Automate DBA Tasks With Ansible)
 
Ansible is Our Wishbone
Ansible is Our WishboneAnsible is Our Wishbone
Ansible is Our Wishbone
 
Installing AtoM with Ansible
Installing AtoM with AnsibleInstalling AtoM with Ansible
Installing AtoM with Ansible
 
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)
Introduction to Ansible - (dev ops for people who hate devops)
 
Ansible
AnsibleAnsible
Ansible
 
Automating with ansible (Part A)
Automating with ansible (Part A)Automating with ansible (Part A)
Automating with ansible (Part A)
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdf
 
Ansible - Hands on Training
Ansible - Hands on TrainingAnsible - Hands on Training
Ansible - Hands on Training
 
A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of Ansible
 
Ansible & Salt - Vincent Boon
Ansible & Salt - Vincent BoonAnsible & Salt - Vincent Boon
Ansible & Salt - Vincent Boon
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
Introducing Ansible
Introducing AnsibleIntroducing Ansible
Introducing Ansible
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practices
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
 
Ansible_Basics_ppt.pdf
Ansible_Basics_ppt.pdfAnsible_Basics_ppt.pdf
Ansible_Basics_ppt.pdf
 
ansible : Infrastructure automation,idempotent and more
ansible : Infrastructure automation,idempotent and moreansible : Infrastructure automation,idempotent and more
ansible : Infrastructure automation,idempotent and more
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

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