Testing with a playbook
One of the most complex things in the IT field is not creating software and systems but debugging them when they have problems. Ansible is no exception. No matter how good you are at creating Ansible playbooks, sooner or later, you’ll find yourself debugging a playbook that is not behaving as you thought it would.
The simplest way of performing basic tests is to print out the values of variables during execution. Let’s learn how to do this with Ansible:
- First of all, we need a playbook called
debug.yaml
with the following content:--- - hosts: localhost tasks: - ansible.builtin.shell: /usr/bin/uptime register: result - ansible.builtin.debug: var: result
- Run it with the following command:
$ ansible-playbook debug.yaml
You will receive an output similar to the following:
PLAY [localhost] *******************************************...