Ansible
Ansible⚑
Usage⚑
Meta⚑
Run handlers (before): - meta: flush_handlers
(http://docs.ansible.com/ansible/playbooks_intro.html#handlers-running-operations-on-change)
Loops⚑
Looping over Subelements⚑
Useful when you have a list of dictionaries and you want to pick the same element from all of them.
with_subelements:
- "{{ some list }}"
- interesting_list_item
- flags:
skip_missing: yes
(https://docs.ansible.com/ansible/latest/playbooks_loops.html#looping-over-subelements)
Command line⚑
Variables⚑
To provide variables directly from the command line: --extra-vars "version=1.23.45 other_variable=foo"
.
Facts⚑
ansible_user_id
Only gather facts when tag matches⚑
To speed up playbooks, disable gather_facts
. In the parts where this is requiered, you can use this approach:
- hosts: all
sudo: yes
gather_facts: False
pre_tasks:
- setup:
filter: ansible_*
roles:
- your_role_here
tags:
- tag1
This way ansible will only gather some facts and only if the tag matches (when run with the -t
option).
Debug⚑
Include tags ignored⚑
Example:
- import_tasks: db-setup.yml tags=db-setup
This tags are ignored if you skip them. Bug: (https://github.com/ansible/ansible/issues/9862)
could not find item
key in iterated item⚑
Solution: specify a third element in the with_subelements list called flags that is a dict and contains skip_missing: yes.
with_subelements:
- "{{ some list }}"
- interesting_list_item
- flags:
skip_missing: yes
(https://github.com/ansible/ansible/pull/10995)
Reference⚑
Usage⚑
Modules⚑
- (https://docs.ansible.com/ansible/latest/mysql_db_module.html)
- (https://docs.ansible.com/ansible/latest/docker_container_module.html)
Utilities⚑
- (https://github.com/nickjj/ansigenome) Tool for calculating dependency graphs and more.
Vault⚑
Plugins⚑
Timing⚑
Displays tasks timing at the end of the playbook output.
To enable, add callback_whitelist = profile_tasks
to ansible.cfg.