RIPE71-16NOV2015
RIPE71-16NOV2015
Ansible 101
RIPE 71 - November 16th, 2015
Introduction Tutorial
http://git.io/vZKZH
Knowledge
http://git.io/vZKZH
Environment
Officially supported! Not supported, but
can work (Cygwin)
http://git.io/vZKZH
Virtual environment
http://git.io/vZKZH
Packages
Essentially…
http://git.io/vZKZH
What if I don’t have any of that...
Monitoring Scripts, based on importance Vendor & home grown Vendor & home grown
Got {Net}DevOps?
An industry in transition
Or… is your job in jeopardy?
DevOps
● Unite people and {organization appropriate} methods
○ Typically Developers & Operations staff
○ Shared service(s) availability responsibility
● Infrastructure as code
reference:
pkgs: openssh, apache
Signalling
agent
software installed on remote
hardware to interface with
agent’less
no specific software installed on
remote hardware
How Puppet* works
← (agent)
→
SSL
→ *
SSH
localhost
So, why did we pick Ansible?
1. agent’less
2. low risk (run it locally)
3. small investment
4. easy to learn
Terminology
WARNING!
(Sorry.)
YAML
# EXAMPLE DATA FILE 1
● Human readable data
roles:
format / alternative to XML - { who: dev, name: Ian }
- { who: noc, name: Alice }
● More powerful than CSV
# EXAMPLE DATA FILE 2
○ Data can imply it’s a list,
integer, string, etc. roles:
noc:
name: Alice
● Filename extension .yml dev:
name: Ian
Jinja2
## EXAMPLE TEMPLATE ● Python template engine
● Enumerates files using
Employees
{ for a,b in roles } variable data
Role: { item.a } ● Supports conditionals:
Name: { item.b } ○ If statements
{ endfor }
○ Loops
○ Piping
● Ansible standard file
extension .j2
Hosts
# EXAMPLE HOSTS LIST
[dev]
● Group host addresses, test-switch1 mgmt_ip=10.1.10.1
assign names, specify 100.0.0.42
variables, etc. dev-router4
● Default is /etc/ansible/hosts [prod]
○ can override this easily mywebsite.com
172.16.0.56 name=dev42.prod
172.16.0.17
Playbooks
---
- name: Generate configs
hosts: localhost
● Specifies execution
gather_facts: no ● Single or multiple OK
● You can write all tasks and
roles:
- router
vars in a playbook...
- switch ○ … but not recommended
Facts
# EXAMPLE SYSTEM FACTS
● Gathers information on the
"ansible_architecture":
remote host(s) "x86_64",
○ Hardware, OS, uptime, "ansible_bios_date":
MAC address & more "09/20/2012",
● You can use this info like a "ansible_bios_version":
"6.00",
regular variable data point
Inventory
[EXAMPLE DIRECTORY/FILE ● Allows you to pass in
STRUCTURE] specific data with
different playbooks
myplaybook.yml
roles
● Can specify hosts,
inventory group vars, and host-
hosts specific vars
group_vars
sites.yml
● Can be accessed
across multiple roles
Roles
[EXAMPLE DIRECTORY/FILE
● A built-in structure for STRUCTURE]
compartmentalizing ansible
● Roles make it easy / myplaybook.yml
clean to manage roles
router
execution
tasks
● Makes scaling and templates
collaboration easier! switch
tasks
Hands-on: config generation
General outline
● Inventory + Roles
● Variables
● Templates
● IP Address Filter
● Tasks
● Hosts
● Playbook
Hello world
Hello world
(before)
Hello world
(after)
Structure
├── myplaybook.yml
├── inventory
│ ├── group_vars
│ │ └── sites.yml ● Lots of ways to structure
│ └── hosts
└── roles
○ Use roles?
├── router ○ Use an inventory?
│ ├── tasks ○ Global, group, host variables?
│ │ └── main.yml
│ ├── templates ● Depends on your situation
│ │ └── template1.j2 ● No “right” way
│ └── vars
│ └── main.yml
└── switch
Reference files
Copy these from workspace/reference/
localhost
Playbook
---
● Brings it together:
- name: Create files
○ Hosts
hosts: localhost
○ Roles
connection: local
■ Tasks
gather_facts: no
■ Templates
○ Variables
roles:
● And executes!
- router
Running a play
● Missing packages?
● Missing variables?
● Formatting weirdness?
● Typos?
… and more!
The future...
Maybe an Ansible 201 tutorial...?
● Advanced templating techniques
[email protected] @bronwyn
[email protected] @dorkmatt