Using the preview or dry run option
When coding an Ansible playbook, we often need to test different steps without applying them directly to infrastructure. Hence, it is very useful, especially in the automation of VM configuration with Ansible, to have a preview of its execution, to check that the syntax of the playbook is maintaining good consistency with the system configuration that already exists on the host.
With Ansible, it's possible to check the execution of a playbook on hosts by adding the --check option to the command:
ansible-playbook -i inventory playbook.yml --check
Here is an example of this dry run execution:
With this option, Ansible does not apply configuration changes on the host; it only checks and previews the changes made to the hosts.
We have just seen that Ansible allows us to check a playbook before applying it only on a host; it is also necessary to know that there are other tools to test the good functioning of a playbook (without having to simulate its execution), such as Vagrant by HashiCorp.
Vagrant allows us to locally create a test environment composed of VMs very quickly, on which we can really run our playbooks and see the real results of their executions. For more information on the use of Ansible and Vagrant, refer to the documentation here: https://docs.ansible.com/ansible/latest/scenario_guides/guide_vagrant.html.
We have just seen how to preview the changes that will be applied by Ansible. Now, let's look at how to increase the log level output of Ansible's execution.