First line of debugging is reading logs. The default ansible log formats can be intimidating for humans. How can you do?
Change the output format using ansible output callback plugin. The configiguration can be done in ansible.cfg
[defaults]
stdout_callback=debug
SSH connection to hosts sometimes fail. How do you troubleshoot them?
Run the playbook with increased verbose level.
> ansible-playbook -vvv
or
> ansible-playbook -vvvv
You want to see the value of a variable when running the playbook. What do you do?
use the debug module
What is the playbook debugger?
Playbook debugger is an interactive debugger for ansible. When a task fails, ansible drops into the debugger.
How do I enable ansible debugger?
Add the clause “strategy: debug” to the playbook.
How do I navigate the ansible debugger?
using ansinble deugger commands:
p var: print a variable r: rerun the failed task c: continue executing the play q: abort the play task.args[key]=value: modify an argument vars[key]=value modify a variable value
What are example of variables supported by the ansible debugger?
task, result, vars, vars[key], task.args
What is the use of the assert module?
assert module will fail the playbook with an error if a condition is not met.
Provide an example using the assert plugin
What is the language used in assert statement?
Jinja2
I want to assert that /etc/nginx is a directory. What do I do? Write the task.
1) Call the stat module to get stats on the file system
2) Assert of the type of file property that included in the provided stats
Ansible-playbook provides many flags that allow you to inspect or sanitize your playbook before running it. what are these flags?
What mechanisms allow me to restrict the way I can run a playbook?
1) step: ansible prompts me before executing each task
2) start-at-task: start running playbook at given tag
3) –tags: run only tasks with a given tag
How do I tag a task?
Provide a command for running playbook.yml with tags foo and quux
> ansible-playbook –tags=foo,quux playbook.yml
Provide a command for running playbook.yml while skipping tasks tagged with foo and quux
> ansible-playbook –skip-tags=foo,quux playbook.yml