Prior to Ansible 2.0, default filters were allowed
"{{ oracle1.instance.reports|d().forecast|d().email|d('testing@gmail.com') }}"
where |d()
would allow a variable (such as reports
or forecast
) to be defaulted to the default variable at the end (in this case, the default variable is testing@gmail.com
) if the program couldn't find an instance for reports
or forecast
. reports
& forecasts
are defined in some environments, but not in all, so I cannot remove these variables from the script line. In Ansible 2.X, the default filter |d()
is not necessary and the code can be written like this:
"{{ oracle1.instance.reports.forecast.email|d('testing@gmail.com') }}"
When running the script above, I am getting this error:
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'reports'\n\nThe error appears to have been in '/home/ansible/svn/stable-1.6-ansible2_other/playbooks/buildEnvironment/temp2.yml': line 21, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n ignore_errors: false\n - debug:\n ^ here\n"}
Any help on this matter or how to use default variable filters for Ansible 2.X would be much appreciated!
I do it like this: