Ansible
Ansible
Ansible
Timothy Appnel
Senior Product Manager, Ansible
GitHub: tima
Twitter: appnelgroup
THE ANSIBLE WAY
2
COMPLEXITY KILLS PRODUCTIVITY
That's not just a marketing slogan. We really mean it
and believe that. We strive to reduce complexity in
how we've designed Ansible tools and encourage you
to do the same. Strive for simplification in what you
automate.
3
OPTIMIZE FOR READABILITY
If done properly, it can be the documentation of your
workflow automation.
4
Principal 3
THINK DECLARATIVELY
Ansible is a desired state engine by design. If you're
trying to "write code" in your plays and roles, you're
setting yourself up for failure. Our YAML-based
playbooks were never meant to be for programming.
5
WORKFLOW
6
WORKFLOW
Do It with Style
7
PROJECT LAYOUTS: BASIC
basic-project
├── inventory
│ ├── group_vars
│ │ └── web.yml
│ ├── host_vars
│ │ └── db1.yml
│ └── hosts
└── site.yml
8
PROJECT LAYOUTS: ORGANIZATIONAL ROLES
myapp
├── roles
│ ├── myapp
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── ...
│ ├── nginx
│ │ └── ...
│ └── proxy
│ └── ...
└── site.yml
9
PROJECT LAYOUTS: SHARED ROLES
myapp
├── config.yml
├── provision.yml
├── roles
│ └── requirements.yml
└── site.yml
10
INVENTORY
11
INVENTORY
CMDB
PUBLIC / PRIVATE
CLOUD
13
VARIABLES
14
VARIABLES
15
SEPARATE LOGIC FROM VARIABLES
16
SEPARATE LOGIC FROM VARIABLES
18
USE NATIVE YAML SYNTAX
NO!
19
USE NATIVE YAML SYNTAX
Better, but no
20
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
22
PLAYS & TASKS
EXHIBIT A
- hosts: web PLAY [web]
tasks: ********************************
- yum:
name: httpd TASK [setup]
state: latest ********************************
ok: [web1]
23
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]
24
PLAYS & TASKS
25
PLAYS & TASKS
- debug:
msg: "This always displays"
- debug:
msg: "This only displays with ansible-playbook -vv+"
verbosity: 2
26
PLAYS & TASKS
27
PLAYS & TASKS
28
PLAYS & TASKS
29
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
30
PLAYS & TASKS
31
PLAYS & TASKS
acme_corp/
├── configure.yml
├── provision.yml
└── site.yml
$ cat site.yml
---
- import_playbook: provision.yml
- import_playbook: configure.yml
32
TEMPLATES
{{ ansible_managed | comment }}
34
ROLES
35
ROLES
36
SCALING YOUR ANSIBLE WORKFLOW
37
Thank you
38