Configuration Management in Ansible

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/
1 of 27

Recommended

Ansible presentation by
Ansible presentationAnsible presentation
Ansible presentationKumar Y
3.1K views20 slides
Automating with Ansible by
Automating with AnsibleAutomating with Ansible
Automating with AnsibleRicardo Schmidt
825 views27 slides
Introduction to Ansible by
Introduction to AnsibleIntroduction to Ansible
Introduction to AnsibleCoreStack
722 views19 slides
Ansible - Introduction by
Ansible - IntroductionAnsible - Introduction
Ansible - IntroductionStephane Manciot
11.6K views32 slides
Getting started with Ansible by
Getting started with AnsibleGetting started with Ansible
Getting started with AnsibleIvan Serdyuk
498 views83 slides
DevOps with Ansible by
DevOps with AnsibleDevOps with Ansible
DevOps with AnsibleSwapnil Jain
1.8K views19 slides

More Related Content

What's hot

Automation with ansible by
Automation with ansibleAutomation with ansible
Automation with ansibleKhizer Naeem
1.6K views73 slides
Ansible Introduction by
Ansible Introduction Ansible Introduction
Ansible Introduction Robert Reiz
17.7K views35 slides
Ansible presentation by
Ansible presentationAnsible presentation
Ansible presentationSuresh Kumar
7.1K views21 slides
Ansible by
AnsibleAnsible
AnsibleVishal Yadav
5K views39 slides
Introduction to ansible by
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
1.1K views33 slides
Ansible get started by
Ansible get startedAnsible get started
Ansible get startedRafael Cassau
689 views22 slides

What's hot(20)

Automation with ansible by Khizer Naeem
Automation with ansibleAutomation with ansible
Automation with ansible
Khizer Naeem1.6K views
Ansible Introduction by Robert Reiz
Ansible Introduction Ansible Introduction
Ansible Introduction
Robert Reiz17.7K views
Ansible presentation by Suresh Kumar
Ansible presentationAnsible presentation
Ansible presentation
Suresh Kumar7.1K views
Introduction to ansible by Omid Vahdaty
Introduction to ansibleIntroduction to ansible
Introduction to ansible
Omid Vahdaty1.1K views
What Is Ansible? | How Ansible Works? | Ansible Tutorial For Beginners | DevO... by Simplilearn
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...
Simplilearn2.8K views
Ansible, best practices by Bas Meijer
Ansible, best practicesAnsible, best practices
Ansible, best practices
Bas Meijer13.1K views
Introduction to Ansible by Knoldus Inc.
Introduction to AnsibleIntroduction to Ansible
Introduction to Ansible
Knoldus Inc.24.2K views
DevOps Meetup ansible by sriram_rajan
DevOps Meetup   ansibleDevOps Meetup   ansible
DevOps Meetup ansible
sriram_rajan550 views
Ansible tips & tricks by bcoca
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
bcoca24.1K views
Best practices for ansible by George Shuklin
Best practices for ansibleBest practices for ansible
Best practices for ansible
George Shuklin6.8K views

Viewers also liked

Python (Jinja2) Templates for Network Automation by
Python (Jinja2) Templates for Network AutomationPython (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network AutomationRick Sherman
5.4K views21 slides
Ansible 101, Gennadiy Mykhailiuta by
Ansible 101, Gennadiy MykhailiutaAnsible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy MykhailiutaTetiana Saputo
1.2K views34 slides
The Rules of Network Automation - Interop/NYC 2014 by
The Rules of Network Automation - Interop/NYC 2014The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014Jeremy Schulman
3.7K views37 slides
A Network Engineer's Approach to Automation by
A Network Engineer's Approach to AutomationA Network Engineer's Approach to Automation
A Network Engineer's Approach to AutomationJeremy Schulman
8.4K views20 slides
Introductory Presentation of bdNOG by
Introductory Presentation of bdNOGIntroductory Presentation of bdNOG
Introductory Presentation of bdNOGBangladesh Network Operators Group
732 views19 slides
Information Society Innovation Fund (ISIF) Showcase by
Information Society Innovation Fund (ISIF) Showcase Information Society Innovation Fund (ISIF) Showcase
Information Society Innovation Fund (ISIF) Showcase Bangladesh Network Operators Group
608 views8 slides

Viewers also liked(20)

Python (Jinja2) Templates for Network Automation by Rick Sherman
Python (Jinja2) Templates for Network AutomationPython (Jinja2) Templates for Network Automation
Python (Jinja2) Templates for Network Automation
Rick Sherman5.4K views
Ansible 101, Gennadiy Mykhailiuta by Tetiana Saputo
Ansible 101, Gennadiy MykhailiutaAnsible 101, Gennadiy Mykhailiuta
Ansible 101, Gennadiy Mykhailiuta
Tetiana Saputo1.2K views
The Rules of Network Automation - Interop/NYC 2014 by Jeremy Schulman
The Rules of Network Automation - Interop/NYC 2014The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014
Jeremy Schulman3.7K views
A Network Engineer's Approach to Automation by Jeremy Schulman
A Network Engineer's Approach to AutomationA Network Engineer's Approach to Automation
A Network Engineer's Approach to Automation
Jeremy Schulman8.4K views

Similar to Configuration Management in Ansible

Introduction to Ansible - (dev ops for people who hate devops) by
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)Jude A. Goonawardena
106 views22 slides
#OktoCampus - Workshop : An introduction to Ansible by
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
435 views35 slides
MariaDB, MySQL and Ansible: automating database infrastructures by
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresFederico Razzoli
175 views41 slides
Introduction to Ansible - Peter Halligan by
Introduction to Ansible - Peter HalliganIntroduction to Ansible - Peter Halligan
Introduction to Ansible - Peter HalliganCorkOpenTech
108 views23 slides
Ansible automation tool with modules by
Ansible automation tool with modulesAnsible automation tool with modules
Ansible automation tool with modulesmohamedmoharam
709 views18 slides
Learning Puppet basic thing by
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing DaeHyung Lee
1.2K views66 slides

Similar to Configuration Management in Ansible (20)

Introduction to Ansible - (dev ops for people who hate devops) by Jude A. Goonawardena
Introduction to Ansible - (dev ops for people who hate devops)Introduction to Ansible - (dev ops for people who hate devops)
Introduction to Ansible - (dev ops for people who hate devops)
#OktoCampus - Workshop : An introduction to Ansible by Cédric Delgehier
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
Cédric Delgehier435 views
MariaDB, MySQL and Ansible: automating database infrastructures by Federico Razzoli
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructures
Federico Razzoli175 views
Introduction to Ansible - Peter Halligan by CorkOpenTech
Introduction to Ansible - Peter HalliganIntroduction to Ansible - Peter Halligan
Introduction to Ansible - Peter Halligan
CorkOpenTech108 views
Ansible automation tool with modules by mohamedmoharam
Ansible automation tool with modulesAnsible automation tool with modules
Ansible automation tool with modules
mohamedmoharam709 views
Learning Puppet basic thing by DaeHyung Lee
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing
DaeHyung Lee1.2K views
More tips n tricks by bcoca
More tips n tricksMore tips n tricks
More tips n tricks
bcoca5.3K views
Ansible & Salt - Vincent Boon by MyNOG
Ansible & Salt - Vincent BoonAnsible & Salt - Vincent Boon
Ansible & Salt - Vincent Boon
MyNOG998 views
Ansible is Our Wishbone by Mydbops
Ansible is Our WishboneAnsible is Our Wishbone
Ansible is Our Wishbone
Mydbops915 views
Ansible is Our Wishbone(Automate DBA Tasks With Ansible) by M Malai
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)
M Malai292 views
Using Ansible for Deploying to Cloud Environments by ahamilton55
Using Ansible for Deploying to Cloud EnvironmentsUsing Ansible for Deploying to Cloud Environments
Using Ansible for Deploying to Cloud Environments
ahamilton554.2K views
Automating the Cloud with Terraform, and Ansible by Brian Hogan
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and Ansible
Brian Hogan1.8K views
Ansible for beginners by Kuo-Le Mei
Ansible for beginnersAnsible for beginners
Ansible for beginners
Kuo-Le Mei4.9K views
Workflow story: Theory versus practice in Large Enterprises by Puppet
Workflow story: Theory versus practice in Large EnterprisesWorkflow story: Theory versus practice in Large Enterprises
Workflow story: Theory versus practice in Large Enterprises
Puppet3.1K views
Workflow story: Theory versus Practice in large enterprises by Marcin Piebiak by NETWAYS
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
NETWAYS504 views
Ansible is the simplest way to automate. MoldCamp, 2015 by Alex S
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015
Alex S4.4K views
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments by SaltStack
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
SaltStack5K views

More from Bangladesh Network Operators Group

IPv6 Deployment in South Asia 2022 by
IPv6 Deployment in South Asia  2022IPv6 Deployment in South Asia  2022
IPv6 Deployment in South Asia 2022Bangladesh Network Operators Group
43 views20 slides
Introduction to Software Defined Networking (SDN) by
Introduction to Software Defined Networking (SDN)Introduction to Software Defined Networking (SDN)
Introduction to Software Defined Networking (SDN)Bangladesh Network Operators Group
143 views27 slides
RPKI Deployment Status in Bangladesh by
RPKI Deployment Status in BangladeshRPKI Deployment Status in Bangladesh
RPKI Deployment Status in BangladeshBangladesh Network Operators Group
45 views21 slides
An Overview about open UDP Services by
An Overview about open UDP ServicesAn Overview about open UDP Services
An Overview about open UDP ServicesBangladesh Network Operators Group
217 views15 slides
12 Years in DNS Security As a Defender by
12 Years in DNS Security As a Defender12 Years in DNS Security As a Defender
12 Years in DNS Security As a DefenderBangladesh Network Operators Group
111 views21 slides
Contents Localization Initiatives to get better User Experience by
Contents Localization Initiatives to get better User ExperienceContents Localization Initiatives to get better User Experience
Contents Localization Initiatives to get better User ExperienceBangladesh Network Operators Group
77 views31 slides

More from Bangladesh Network Operators Group(20)

Recently uploaded

Amine el bouzalimi by
Amine el bouzalimiAmine el bouzalimi
Amine el bouzalimiAmine EL BOUZALIMI
5 views38 slides
hamro digital logics.pptx by
hamro digital logics.pptxhamro digital logics.pptx
hamro digital logics.pptxtupeshghimire
11 views36 slides
The Dark Web : Hidden Services by
The Dark Web : Hidden ServicesThe Dark Web : Hidden Services
The Dark Web : Hidden ServicesAnshu Singh
19 views24 slides
WITS Deck by
WITS DeckWITS Deck
WITS DeckW.I.T.S.
27 views22 slides
Cracking the Code Decoding Leased Line Quotes for Connectivity Excellence.pptx by
Cracking the Code Decoding Leased Line Quotes for Connectivity Excellence.pptxCracking the Code Decoding Leased Line Quotes for Connectivity Excellence.pptx
Cracking the Code Decoding Leased Line Quotes for Connectivity Excellence.pptxLeasedLinesQuote
5 views8 slides
How to think like a threat actor for Kubernetes.pptx by
How to think like a threat actor for Kubernetes.pptxHow to think like a threat actor for Kubernetes.pptx
How to think like a threat actor for Kubernetes.pptxLibbySchulze1
7 views33 slides

Recently uploaded(10)

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/