Troubleshooting and Testing Strategies

In a similar way to any other kind of code, Ansible code can contain issues and bugs. Ansible tries to make it as safe as possible by checking the task syntax before the task is executed. This check, however, only saves you from a small number of possible types of errors, such as incorrect task parameters, but it will not protect you from others.

It's also important to remember that, due to its nature, in Ansible code, we describe the desired state rather than stating a sequence of steps to obtain the desired state. This difference means that the system is less prone to logical errors.
Nevertheless, a bug in a Playbook could mean a potential misconfiguration on all of your machines. This should be taken very seriously. It is even more critical when critical parts of the system are changed, such as SSH daemon or sudo configuration, since the risk is you locking yourself out of the system.

There are a bunch of different ways to prevent or mitigate a bug in Ansible playbooks. In this chapter, we will cover the following topics:

  • Digging into playbook execution problems
  • Using host facts to diagnose failures
  • Testing with a playbook
  • Using check mode
  • Solving host connection issues
  • Passing working variables via the CLI
  • Limiting the host's execution
  • Flushing the code cache
  • Checking for bad syntax
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset