Bug Report
1.8.2
RHEL 5
The default filter does not resolve variables defined in the inventory.
For example, if I have defined in my inventory file the following variable:
app_install_dir=/test
My playbook has this and "somevariable" is not defined:
dest_dir="{{ somevariable | default('{{app_install_dir}}/DATA') }}"
When running the playbook, the default fails to resolve "app_install_dir"
This used to work on Ansible 1.7.1.
1) Define a variable in the inventory called called "test_directory=/tmp/testdir"
2) In the playbook, have a task to create a directory defined by variable dest={{ undefined_variable | default('{{test_directory}}') }}
3) After running the playbook, it fails to resolve the value of "test_directory"
The default filter should be able to resolve variables
The default filter is not resolving variables defined in inventory
Hi!
Thanks very much for your submission to Ansible. It sincerely means a lot to us.
We believe the ticket you have filed is being somewhat misunderstood, as one thing works a little differently than stated.
dest={{ undefined_variable | default('{{test_directory}}') }}
is an invalid expression , you cannot nest {{ }}, what you probably want is the following:
dest={{ undefined_variable | default(test_directory) }}
In the future, this might be a topic more well suited for the user list, which you can also post here if you'd like some more help with the above.
Thank you once again for this and your interest in Ansible!
@bcoca: Good to know, but does that mean we cannot concatenate a variable and a literal in a default ? Something like: dest={{ undefined_variable | default('{{test_directory}}/subdir') }}
(but not invalid ;-)
I don't normally see posts in closed tickets but an irc user pinged me on this:
dest={{ undefined_variable | default(test_directory + '/subdir') }}
Most helpful comment
I don't normally see posts in closed tickets but an irc user pinged me on this:
dest={{ undefined_variable | default(test_directory + '/subdir') }}