Using host facts to diagnose failures
Some execution failures derive from the state of the target machine. The most common problem of this kind is the case where Ansible expects a file or variable to be present, but it’s not there.
Sometimes, it can be enough to print the machine facts to find the problem.
To do so, we need to create a simple playbook called print_facts.yaml
, which contains the following content:
--- - hosts: all tasks: - name: Display all variables/facts known for a host ansible.builtin.debug: var: hostvars[inventory_hostname]
This technique will give you a lot of information about the state of the target machine during Ansible execution.