One thing that can help during debugging, and definitely helps for code reusability, is passing variables to playbooks via the command line. Every time your application – either an Ansible playbook or any kind of application – receives an input from a third party (a human, in this case), it should ensure that the value is reasonable. An example of this would be to check that the variable has been set and therefore is not an empty string. This is a security golden rule, but should also be applied when the user is trusted since the user might mistype the variable name. The application should identify this and protect the whole system by protecting itself. Follow these steps:
- The first thing we want to have is a simple playbook that prints the content of a variable. Let's create a playbook called printvar.yaml that contains...