6. YAML example
---
acronym: TARDIS
full_name: Time And Relative Dimension In Space
other_names:
- the ship
- the blue box
- the police box
occupants:
- name: The Doctor
role: Timelord
hearts: 2
- name: Amelia Pond
role: Companion
26. jinja2 filter definitions.
You will write them to simplify your playbooks.
{{ my_var|upper }}
{{ registered_var|changed }}
{{ other_var|lower|rot13 }}
30. Templating engine is Jinja2.
Allows for easy content customization.
A template has access to:
host and group variables,
facts and registered playbook variables.
Simple flow control:
loops, conditionals, includes, ...
36. a role is a set of tasks
e.g.
---
- apt_key:
id: BBEBDCB318AD50EC6865090613B00F1FD2C19886
keyserver: keyserver.ubuntu.com
- apt_repository:
repo: deb http://repository.spotify.com testing non-free
- apt:
update_cache: yes
- apt:
name: spotify-client
cache_valid_time: 2600
46. Keep your roles separate from your inventory
roles/ # roles repository
environments/ # environment repository
production/
prod1
prod2
staging/
stage1
stage2
47. A directory is also a file,
production/ # inventory DIRECTORY
webservers
cache
monitoring
wtf
omg
48. Keep your group and host vars
alongside the inventory
environments/
production/
prod1/
inventory
group_vars/
host_vars/
49. specify the environment during runtime
ansible-playbook -i
environments/production/prod1/inventory
(or make an alias for that)
This way you will not run a playbook
on a wrong environment
50. Don't keep playbooks in the main directory.
Use a tree structure:
plays/
monitoring/
set_up_wtf_mon.yml
deploy/
application1.yml
security/
add_ssh_user.yml
51. Add an environment variable
pointing to the roles' root dir.
export ANSIBLE_ROLES_PATH=
~/git/orchestration/roles
That way your playbooks will
always see roles that they use.
63. » linear: classic strategy, a task
is run on every host,
then move to new task
» free: run all tasks on all hosts
as quickly as possible,
but still in-order