Professional Documents
Culture Documents
GitHub/freenode: mglantz
http://github.com/mglantz/presentations
Ansible HOW DOES IT WORK?
Public / Private
Cloud CMDB
ANSIBLE AUTOMATION
Hosts
Networking
Modules Projects
Projects
THE ANSIBLE WAY
3
Principal 1 - COMPLEXITY KILLS PRODUCTIVITY
Heey… Do you know what
^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[
13-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-
9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[
2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:
Now 5 years 16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9
We need to automate later ])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:
1[6-9]|[2-9]\d)?\d{2})$
...does?
No problem. I’m Phil. I’ll Phil wrote that, good luck, he got killed
have this automated in a bit. in the great dog-regexp war of 2019.
4
Principal 2 - OPTIMIZE FOR READABILITY
5
Principal 3 - THINK DECLARATIVELY
6
WORKFLOW
7
WORKFLOW
Also I deserve
a demo. ...
11
WORKFLOW
Do It with Style
12
TESTING WORKFLOW
Read more
https://github.com/mglantz/ansible-roadshow/tree/master/labs/lab-9
13
PROJECT LAYOUTS: BASIC
basic-project
├── inventory
│ ├── group_vars
│ │ └── web.yml
│ ├── host_vars
│ │ └── db1.yml
│ └── hosts
└── site.yml
14
PROJECT LAYOUTS: ORGANIZATIONAL ROLES
myapp
├── roles
│ ├── myapp
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── ...
│ ├── nginx
│ │ └── ...
│ └── proxy
│ └── ...
└── site.yml
15
PROJECT LAYOUTS: SHARED ROLES
myapp
├── config.yml
├── provision.yml
├── roles
│ └── requirements.yml
└── site.yml
16
INVENTORY
17
INVENTORY
CMDB
PUBLIC / PRIVATE
CLOUD
19
VARIABLES
20
SEPARATE LOGIC FROM VARIABLES
21
SEPARATE LOGIC FROM VARIABLES
23
USE NATIVE YAML SYNTAX
NO!
24
USE NATIVE YAML SYNTAX
Better, but no
25
USE NATIVE YAML SYNTAX
Yes!
- name: install telegraf
yum:
name: telegraf-{{ telegraf_version }}
state: present
update_cache: yes
disable_gpg_check: yes
enablerepo: telegraf
notify: restart telegraf
27
PLAYS & TASKS
EXHIBIT A
- hosts: web PLAY [web]
tasks: ********************************
- yum:
name: httpd TASK [setup]
state: latest ********************************
ok: [web1]
28
PLAYS & TASKS
EXHIBIT B
PLAY [install and start apache]
- hosts: web
********************************
name: install and start apache
tasks:
TASK [setup]
- name: install apache packages
********************************
yum:
ok: [web1]
name: httpd
state: latest
TASK [install apache packages]
********************************
- name: start apache service
ok: [web1]
service:
name: httpd
TASK [start apache service]
state: started
********************************
enabled: yes
ok: [web1]
29
PLAYS & TASKS
30
PLAYS & TASKS
- debug:
msg: "This always displays"
- debug:
msg: "This only displays with ansible-playbook -vv+"
verbosity: 2
31
PLAYS & TASKS
32
PLAYS & TASKS
33
PLAYS & TASKS
34
PLAYS & TASKS
- hosts: all
vars:
cert_store: /etc/mycerts
cert_name: my cert
tasks:
- name: check cert
shell: certify --list --name={{ cert_name }} --cert_store={{ cert_store }} | grep "{{ cert_name }}"
register: output
35
PLAYS & TASKS
36
PLAYS & TASKS
acme_corp/
├── configure.yml
├── provision.yml
└── site.yml
$ cat site.yml
---
- import_playbook: provision.yml
- import_playbook: configure.yml
37
TEMPLATES
{{ ansible_managed | comment }}
39
ROLES
Keep in mind
40
ROLES
41
SCALING YOUR ANSIBLE WORKFLOW
42
Complexity kills productivity
Optimize for readability
Think declaratively
43
Thank you
44