HI y’all,
I switched to a new computer, so this is a clean installation of ansible etc.
One of my playbooks is not working properly. I tracked it down to using a template and one of the variables isn’t defined.
Here’s the scenario:
role/tasks/main.yml:
you can set:
error_on_undefined_vars = False
in ansible.cfg, but this will also skip any errors in templating in plays.
Use defaults, to handle undefined variables without ignoring errors:
ServerAlias: {{ foo | default(‘bar’) }}
Thank you Brian and Arthur.
I already had the error_on_undefined_vars set to False.
Based on Brian’s comment I am going to switch to not having undefined variables - tlooks like my original approach is a code-smell.
However, I still believe there is a bug here, probably introduced in a recent version of Ansible… My current version is:
ansible-playbook 2.2.1.0
My previous version is unknown, but probably a year and a half old.
The bug is that if a variable is undefined for a template, no substitutions at all are occurring, leaving the bracket notation in place. In the old version, substitutions for defined variables would occur, and for undefined variables they would be replaced with the empty string.
Thanks again,
John