SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Introduction to Ansible
Brian Candler
Network Startup Resource Center
brian@nsrc.org
Are your servers Pets or Cattle?
Source:
http://www.slideshare.net/gmccance/cern-data-centre-evolution
What is Ansible?
● A configuration management tool
● Applies changes to your system to bring it to a
desired state
● Similar applications include puppet, chef, salt,
juju, cfengine
Why choose Ansible?
● Target system requires only sshd and python
– No daemons or agents to install
● Security
– Relies on ssh
● Easy to get started, compared to the others!
Ansible running with cowsay
____________________________
< TASK: [install /etc/hosts] >
----------------------------
 ^__^
 (oo)_______
(__) )/
||----w |
|| ||
ok: [pc1.example.com]
Modules
● Ansible “modules” are small pieces of code
which perform one function
– e.g. copy a file, start or stop a daemon
● Most are “idempotent”: means that they only do
something when a change is required
● Many modules supplied as standard
– http://docs.ansible.com/modules.html
Invoking modules from shell
$ ansible s1.ws.nsrc.org -m service 
-a "name=apache2 state=running"
Host or group Module name
Module arguments
Configuring Ansible behaviour
● Tasks are modules called with specific
arguments
● Handlers are triggered when something
changes
– e.g. restart daemon when a config file is changed
● Roles are re-usable bundles of tasks, handlers
and templates
● All defined using YAML
Diversion: YAML
● A way of storing structured data as text
● Conceptually similar to JSON
– String and numeric values
– Lists: ordered sequences
– Hashes: unordered groups of key-value pairs
● String values don't normally need quotes
● Lists and hashes can be nested
● Indentation used to define nesting
YAML list (ordered sequence)
● Single line form
● Multi-line form
[birth, taxes, death]
- birth
- taxes
- death
Space after dash required
YAML hash (key-value pairs)
● Single line form
● Multi-line form
{item: shirt, colour: red, size: 42}
item: shirt
colour: red
size: 42
description: |
this is a very long multi-line
text field which is all one value
Space after colon required
Nesting: list of hashes
● Compact
● Multi-line
- {item: shirt, colour: red, size: 42}
- {item: shirt, colour: blue, size: 44}
- item: shirt
colour: red
size: 42
- item: shirt
colour: blue
size: 44
Note alignment
More complex YAML example
- do: laundry
items:
- trousers
- shirts
- do: polish
items:
- shoes
- buckle
- do: relax
eat:
- chocolate
- chips
A list with 3 items
Each item is a hash (key-value pairs)
Simple value
List value (note indentation)
Ansible playbook
- hosts:
- pc1.example.com
- pc3.example.com
tasks:
- name: install Apache
action: apt pkg=apache2 state=present
- name: ensure Apache is running
action: service name=apache2 state=running
- hosts: dns_servers
roles:
- dns_server
- ntp
Top level: a list of "plays"
Each play has "hosts" plus "tasks" and/or "roles"
Roles
● A bundle of related tasks/handlers/templates
roles/<rolename>/tasks/main.yml
roles/<rolename>/handlers/main.yml
roles/<rolename>/defaults/main.yml
roles/<rolename>/files/...
roles/<rolename>/templates/...
### Recommended way to make re-usable configs
### Not all these files need to be present
Tags
● Each role or individual task can be labelled with
one or more "tags"
● When you run a playbook, you can tell it only to
run tasks with a particular tag: -t <tag>
● Lets you selectively run parts of playbooks
Inventory
● Lists all hosts which Ansible may manage
● Simple "INI" format, not YAML
● Can define groups of hosts
● Default is /etc/ansible/hosts
– We will instead use ./hosts.local
– Can override using -i <filename>
Inventory (hosts) example
[dns_servers]
pc1.example.com
pc2.example.com
[misc]
pc3.example.com
pc4.example.com
# Note: the same host can be listed under
# multiple groups.
# Group "all" is created automatically.
Name of group
Hosts in this group
Inventory variables
● You can set variables on hosts or groups of
hosts
● Variables can make tasks behave differently
when applied to different hosts
● Variables can be inserted into templates
● Some variables control how Ansible connects
Setting host vars
● Directly in the inventory (hosts) file
● In file host_vars/pc2.example.com
[core_servers]
pc1.example.com ansible_connection=local
pc2.example.com
ansible_ssh_host: 10.10.0.241
ansible_ssh_user: root
flurble:
- foo
- bar
# This is in YAML and is preferred
Setting group vars
● group_vars/dns_servers
● group_vars/all
# More YAML
flurble:
- baz
- qux
# More YAML, applies to every host
# Note: host vars take priority over group vars
"Facts"
● Facts are variables containing information
collected automatically about the target host
● Things like what OS is installed, what interfaces
it has, what disk drives it has
● Can be used to adapt roles automatically to the
target system
● Gathered every time Ansible connects to a host
(unless playbook has "gather_facts: no")
Showing facts
$ ansible s1.ws.nsrc.org -m setup | less
s1.ws.nsrc.org | success >> {
"ansible_facts": {
"ansible_distribution": "Ubuntu",
"ansible_distribution_version": "12.04",
"ansible_domain": "ws.nsrc.org",
"ansible_eth0": {
"ipv4": {
"address": "10.10.0.241",
"netmask": "255.255.255.0",
"network": "10.10.0.0"
}, … etc
Invoke the "setup" module
jinja2 template examples
● Insert a variable into text
● Looping over lists
INTERFACES="{{ dhcp_interface }}"
search ws.nsrc.org
{% for host in use_dns_servers %}
nameserver {{ host }}
{% endfor %}
Many other cool features
● Conditionals
● Loops
- action: apt pkg=apache2 state=present
when: ansible_os_family=='Debian'
- action: apt pkg={{item}} state=present
with_items:
- openssh-server
- acpid
- rsync
- telnet
Getting up-to-date Ansible
● Your package manager's version may be old
● For Ubuntu LTS: use the PPA
apt-get install python-software-properties
add-apt-repository ppa:rquillo/ansible
apt-get update
apt-get install ansible
More info and documentation
● http://docs.ansible.com/
● http://docs.ansible.com/faq.html
● http://jinja.pocoo.org/docs/templates/

Más contenido relacionado

La actualidad más candente

What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
Simplilearn
 

La actualidad más candente (20)

Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
ansible why ?
ansible why ?ansible why ?
ansible why ?
 
Ansible, best practices
Ansible, best practicesAnsible, best practices
Ansible, best practices
 
Automating with Ansible
Automating with AnsibleAutomating with Ansible
Automating with Ansible
 
Ansible
AnsibleAnsible
Ansible
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO...
 
Ansible 101
Ansible 101Ansible 101
Ansible 101
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
Ansible intro
Ansible introAnsible intro
Ansible intro
 
Ansible get started
Ansible get startedAnsible get started
Ansible get started
 
Ansible
AnsibleAnsible
Ansible
 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done right
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Ansible - Hands on Training
Ansible - Hands on TrainingAnsible - Hands on Training
Ansible - Hands on Training
 
[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용[1A7]Ansible의이해와활용
[1A7]Ansible의이해와활용
 
Ansible
AnsibleAnsible
Ansible
 
DevOps with Ansible
DevOps with AnsibleDevOps with Ansible
DevOps with Ansible
 

Destacado

Destacado (20)

Python (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network AutomationPython (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network Automation
 
Ansible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaAnsible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy Mykhailiuta
 
The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014
 
A Network Engineer's Approach to Automation
A Network Engineer's Approach to AutomationA Network Engineer's Approach to Automation
A Network Engineer's Approach to Automation
 
Introductory Presentation of bdNOG
Introductory Presentation of bdNOGIntroductory Presentation of bdNOG
Introductory Presentation of bdNOG
 
Information Society Innovation Fund (ISIF) Showcase
Information Society Innovation Fund (ISIF) Showcase Information Society Innovation Fund (ISIF) Showcase
Information Society Innovation Fund (ISIF) Showcase
 
Driver Distraction Management Using Sensor Data Cloud
Driver Distraction Management Using Sensor Data Cloud Driver Distraction Management Using Sensor Data Cloud
Driver Distraction Management Using Sensor Data Cloud
 
Internet Measurement Network
Internet Measurement Network Internet Measurement Network
Internet Measurement Network
 
ICANN Security, Stability and Resiliency Plans & Framework
ICANN Security, Stability and Resiliency Plans & Framework ICANN Security, Stability and Resiliency Plans & Framework
ICANN Security, Stability and Resiliency Plans & Framework
 
Internet Development Experiences and Lessons
Internet Development Experiences and Lessons Internet Development Experiences and Lessons
Internet Development Experiences and Lessons
 
Engaging with Internet Society
Engaging with Internet SocietyEngaging with Internet Society
Engaging with Internet Society
 
Network Security Best Practice (BCP38 & 140)
Network Security Best Practice (BCP38 & 140) Network Security Best Practice (BCP38 & 140)
Network Security Best Practice (BCP38 & 140)
 
IPv6 Deployment Status in Bangladesh
IPv6 Deployment Status in Bangladesh IPv6 Deployment Status in Bangladesh
IPv6 Deployment Status in Bangladesh
 
Discovering and Participating at ICANN
Discovering and Participating at ICANNDiscovering and Participating at ICANN
Discovering and Participating at ICANN
 
IRR Toolset, RPSL
IRR Toolset, RPSL IRR Toolset, RPSL
IRR Toolset, RPSL
 
Application of local Internet content
Application of local Internet content Application of local Internet content
Application of local Internet content
 
Fast Convergence in IP Network
Fast Convergence in IP Network Fast Convergence in IP Network
Fast Convergence in IP Network
 
Cyber Security law in Bangladesh
Cyber Security law in Bangladesh Cyber Security law in Bangladesh
Cyber Security law in Bangladesh
 
Distributed IP-PBX
Distributed IP-PBX Distributed IP-PBX
Distributed IP-PBX
 
History and Evolution of Bangladesh Internet
History and Evolution of Bangladesh Internet History and Evolution of Bangladesh Internet
History and Evolution of Bangladesh Internet
 

Similar a Configuration Management in Ansible

Ansible automation tool with modules
Ansible automation tool with modulesAnsible automation tool with modules
Ansible automation tool with modules
mohamedmoharam
 

Similar a Configuration Management in Ansible (20)

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)
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 
MariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructures
 
Introduction to Ansible - Peter Halligan
Introduction to Ansible - Peter HalliganIntroduction to Ansible - Peter Halligan
Introduction to Ansible - Peter Halligan
 
Ansible automation tool with modules
Ansible automation tool with modulesAnsible automation tool with modules
Ansible automation tool with modules
 
Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
 
Introducing Ansible
Introducing AnsibleIntroducing Ansible
Introducing Ansible
 
Ansible & Salt - Vincent Boon
Ansible & Salt - Vincent BoonAnsible & Salt - Vincent Boon
Ansible & Salt - Vincent Boon
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdf
 
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
 
Using Ansible for Deploying to Cloud Environments
Using Ansible for Deploying to Cloud EnvironmentsUsing Ansible for Deploying to Cloud Environments
Using Ansible for Deploying to Cloud Environments
 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and Ansible
 
Ansible for beginners
Ansible for beginnersAnsible for beginners
Ansible for beginners
 
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin PiebiakWorkflow story: Theory versus Practice in large enterprises by Marcin Piebiak
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak
 
Workflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large EnterprisesWorkflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large Enterprises
 
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
 
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
 
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability EnvironmentsSaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
 

Más de Bangladesh Network Operators Group

Más de Bangladesh Network Operators Group (20)

Accelerating Hyper-Converged Enterprise Virtualization using Proxmox and Ceph
Accelerating Hyper-Converged Enterprise Virtualization using Proxmox and CephAccelerating Hyper-Converged Enterprise Virtualization using Proxmox and Ceph
Accelerating Hyper-Converged Enterprise Virtualization using Proxmox and Ceph
 
Recent IRR changes by Yoshinobu Matsuzaki, IIJ
Recent IRR changes by Yoshinobu Matsuzaki, IIJRecent IRR changes by Yoshinobu Matsuzaki, IIJ
Recent IRR changes by Yoshinobu Matsuzaki, IIJ
 
Fact Sheets : Network Status in Bangladesh
Fact Sheets : Network Status in BangladeshFact Sheets : Network Status in Bangladesh
Fact Sheets : Network Status in Bangladesh
 
AI Driven Wi-Fi for the Bottom of the Pyramid
AI Driven Wi-Fi for the Bottom of the PyramidAI Driven Wi-Fi for the Bottom of the Pyramid
AI Driven Wi-Fi for the Bottom of the Pyramid
 
IPv6 Security Overview by QS Tahmeed, APNIC RCT
IPv6 Security Overview by QS Tahmeed, APNIC RCTIPv6 Security Overview by QS Tahmeed, APNIC RCT
IPv6 Security Overview by QS Tahmeed, APNIC RCT
 
Network eWaste : Community role to manage end of life Product
Network eWaste : Community role to manage end of life ProductNetwork eWaste : Community role to manage end of life Product
Network eWaste : Community role to manage end of life Product
 
A plenarily integrated SIEM solution and it’s Deployment
A plenarily integrated SIEM solution and it’s DeploymentA plenarily integrated SIEM solution and it’s Deployment
A plenarily integrated SIEM solution and it’s Deployment
 
IPv6 Deployment in South Asia 2022
IPv6 Deployment in South Asia  2022IPv6 Deployment in South Asia  2022
IPv6 Deployment in South Asia 2022
 
Introduction to Software Defined Networking (SDN)
Introduction to Software Defined Networking (SDN)Introduction to Software Defined Networking (SDN)
Introduction to Software Defined Networking (SDN)
 
RPKI Deployment Status in Bangladesh
RPKI Deployment Status in BangladeshRPKI Deployment Status in Bangladesh
RPKI Deployment Status in Bangladesh
 
An Overview about open UDP Services
An Overview about open UDP ServicesAn Overview about open UDP Services
An Overview about open UDP Services
 
12 Years in DNS Security As a Defender
12 Years in DNS Security As a Defender12 Years in DNS Security As a Defender
12 Years in DNS Security As a Defender
 
Contents Localization Initiatives to get better User Experience
Contents Localization Initiatives to get better User ExperienceContents Localization Initiatives to get better User Experience
Contents Localization Initiatives to get better User Experience
 
BdNOG-20220625-MT-v6.0.pptx
BdNOG-20220625-MT-v6.0.pptxBdNOG-20220625-MT-v6.0.pptx
BdNOG-20220625-MT-v6.0.pptx
 
Route Leak Prevension with BGP Community
Route Leak Prevension with BGP CommunityRoute Leak Prevension with BGP Community
Route Leak Prevension with BGP Community
 
Tale of a New Bangladeshi NIX
Tale of a New Bangladeshi NIXTale of a New Bangladeshi NIX
Tale of a New Bangladeshi NIX
 
MANRS for Network Operators
MANRS for Network OperatorsMANRS for Network Operators
MANRS for Network Operators
 
Re-define network visibility for capacity planning & forecasting with Grafana
Re-define network visibility for capacity planning & forecasting with GrafanaRe-define network visibility for capacity planning & forecasting with Grafana
Re-define network visibility for capacity planning & forecasting with Grafana
 
RPKI ROA updates
RPKI ROA updatesRPKI ROA updates
RPKI ROA updates
 
Blockchain Demystified
Blockchain DemystifiedBlockchain Demystified
Blockchain Demystified
 

Último

Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
sexy call girls service in goa
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Chandigarh Call girls 9053900678 Call girls in Chandigarh
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Sheetaleventcompany
 

Último (20)

Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 

Configuration Management in Ansible

  • 1. Introduction to Ansible Brian Candler Network Startup Resource Center brian@nsrc.org
  • 2. Are your servers Pets or Cattle? Source: http://www.slideshare.net/gmccance/cern-data-centre-evolution
  • 3. What is Ansible? ● A configuration management tool ● Applies changes to your system to bring it to a desired state ● Similar applications include puppet, chef, salt, juju, cfengine
  • 4. Why choose Ansible? ● Target system requires only sshd and python – No daemons or agents to install ● Security – Relies on ssh ● Easy to get started, compared to the others!
  • 5. Ansible running with cowsay ____________________________ < TASK: [install /etc/hosts] > ---------------------------- ^__^ (oo)_______ (__) )/ ||----w | || || ok: [pc1.example.com]
  • 6. Modules ● Ansible “modules” are small pieces of code which perform one function – e.g. copy a file, start or stop a daemon ● Most are “idempotent”: means that they only do something when a change is required ● Many modules supplied as standard – http://docs.ansible.com/modules.html
  • 7. Invoking modules from shell $ ansible s1.ws.nsrc.org -m service -a "name=apache2 state=running" Host or group Module name Module arguments
  • 8. Configuring Ansible behaviour ● Tasks are modules called with specific arguments ● Handlers are triggered when something changes – e.g. restart daemon when a config file is changed ● Roles are re-usable bundles of tasks, handlers and templates ● All defined using YAML
  • 9. Diversion: YAML ● A way of storing structured data as text ● Conceptually similar to JSON – String and numeric values – Lists: ordered sequences – Hashes: unordered groups of key-value pairs ● String values don't normally need quotes ● Lists and hashes can be nested ● Indentation used to define nesting
  • 10. YAML list (ordered sequence) ● Single line form ● Multi-line form [birth, taxes, death] - birth - taxes - death Space after dash required
  • 11. YAML hash (key-value pairs) ● Single line form ● Multi-line form {item: shirt, colour: red, size: 42} item: shirt colour: red size: 42 description: | this is a very long multi-line text field which is all one value Space after colon required
  • 12. Nesting: list of hashes ● Compact ● Multi-line - {item: shirt, colour: red, size: 42} - {item: shirt, colour: blue, size: 44} - item: shirt colour: red size: 42 - item: shirt colour: blue size: 44 Note alignment
  • 13. More complex YAML example - do: laundry items: - trousers - shirts - do: polish items: - shoes - buckle - do: relax eat: - chocolate - chips A list with 3 items Each item is a hash (key-value pairs) Simple value List value (note indentation)
  • 14. Ansible playbook - hosts: - pc1.example.com - pc3.example.com tasks: - name: install Apache action: apt pkg=apache2 state=present - name: ensure Apache is running action: service name=apache2 state=running - hosts: dns_servers roles: - dns_server - ntp Top level: a list of "plays" Each play has "hosts" plus "tasks" and/or "roles"
  • 15. Roles ● A bundle of related tasks/handlers/templates roles/<rolename>/tasks/main.yml roles/<rolename>/handlers/main.yml roles/<rolename>/defaults/main.yml roles/<rolename>/files/... roles/<rolename>/templates/... ### Recommended way to make re-usable configs ### Not all these files need to be present
  • 16. Tags ● Each role or individual task can be labelled with one or more "tags" ● When you run a playbook, you can tell it only to run tasks with a particular tag: -t <tag> ● Lets you selectively run parts of playbooks
  • 17. Inventory ● Lists all hosts which Ansible may manage ● Simple "INI" format, not YAML ● Can define groups of hosts ● Default is /etc/ansible/hosts – We will instead use ./hosts.local – Can override using -i <filename>
  • 18. Inventory (hosts) example [dns_servers] pc1.example.com pc2.example.com [misc] pc3.example.com pc4.example.com # Note: the same host can be listed under # multiple groups. # Group "all" is created automatically. Name of group Hosts in this group
  • 19. Inventory variables ● You can set variables on hosts or groups of hosts ● Variables can make tasks behave differently when applied to different hosts ● Variables can be inserted into templates ● Some variables control how Ansible connects
  • 20. Setting host vars ● Directly in the inventory (hosts) file ● In file host_vars/pc2.example.com [core_servers] pc1.example.com ansible_connection=local pc2.example.com ansible_ssh_host: 10.10.0.241 ansible_ssh_user: root flurble: - foo - bar # This is in YAML and is preferred
  • 21. Setting group vars ● group_vars/dns_servers ● group_vars/all # More YAML flurble: - baz - qux # More YAML, applies to every host # Note: host vars take priority over group vars
  • 22. "Facts" ● Facts are variables containing information collected automatically about the target host ● Things like what OS is installed, what interfaces it has, what disk drives it has ● Can be used to adapt roles automatically to the target system ● Gathered every time Ansible connects to a host (unless playbook has "gather_facts: no")
  • 23. Showing facts $ ansible s1.ws.nsrc.org -m setup | less s1.ws.nsrc.org | success >> { "ansible_facts": { "ansible_distribution": "Ubuntu", "ansible_distribution_version": "12.04", "ansible_domain": "ws.nsrc.org", "ansible_eth0": { "ipv4": { "address": "10.10.0.241", "netmask": "255.255.255.0", "network": "10.10.0.0" }, … etc Invoke the "setup" module
  • 24. jinja2 template examples ● Insert a variable into text ● Looping over lists INTERFACES="{{ dhcp_interface }}" search ws.nsrc.org {% for host in use_dns_servers %} nameserver {{ host }} {% endfor %}
  • 25. Many other cool features ● Conditionals ● Loops - action: apt pkg=apache2 state=present when: ansible_os_family=='Debian' - action: apt pkg={{item}} state=present with_items: - openssh-server - acpid - rsync - telnet
  • 26. Getting up-to-date Ansible ● Your package manager's version may be old ● For Ubuntu LTS: use the PPA apt-get install python-software-properties add-apt-repository ppa:rquillo/ansible apt-get update apt-get install ansible
  • 27. More info and documentation ● http://docs.ansible.com/ ● http://docs.ansible.com/faq.html ● http://jinja.pocoo.org/docs/templates/