Ansible Variable Precedence
- In Ansible we can define the variables at multiple places.
- If the variable is defined only once then that variable will be applied, But if the variable is defined at multiple places (inventory file, host_vars, group_vars, role_defaults,…) then ansible has a precedence for variables
- Refer Here for the official docs
- Refer Here for the change set

- Refer Here for the next change set
Ansible Forks and controlling playbook execution
- Fork: This represents how many parallel nodes can ansible execute. By default ansible is configured to run on 5 nodes
- Ansible forks can be set
- by passing argument to ansible-playbook command (ansible-playbook -f 20 ….)
- Change the ansible.cfg and add the following which applies to all the ansible playbook executions
[defaults] forks = 25
Debugging in Ansible
- In Ansible we can resolve errors in the debugger
- For that add debugger in the play (debugger: on_failed)
- name: test playbook
hosts: all
debugger: on_failed
tasks:
- name: Wrong variable
file:
path: "{{ file_name }}"
state: touch
- name: Learning
debug:
msg: "Learning debugging"
- now execute the playbook

- Available debug commands
| Command | Shortcut | Action |
|---|---|---|
| p | Prints information about the task | |
| task.args[key] = value | no shortcut | Update module args |
| task_vars[key] = value | no shortcut | Update task variables |
| update_task | u | Recreate a task with updated task variables |
| redo | r | Run the task again |
| continue | c | Continue executing, starting with next task |
| quit | q | Quit the debugger |

