-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Jinja2 in dict keys #19664
Support Jinja2 in dict keys #19664
Conversation
Thank you for this pull request, hope it will be merged soon. I really missed this feature. |
Seems useful, but I have to wrap my head around the implications though. |
ce48c81
to
9708485
Compare
This patch allows to use Jinja2 expressions in the key of a dictionary.
9708485
to
b939a8a
Compare
I think this is an improvement over the current syntax that is required for Jinja2 expressions as keys:
|
As discussed in IRC, there is an issue with interdependent keys or overridden keys happening at 'template time' will be subject to dictionary order and not predictable.
Since The 'working dict' has these keys until templated |
@jtyr you're wrong. I was going mad trying to understand how to pass the key of the dict as a variable but after some failed tries, i managed to make it work using the following syntax:
|
@angystardust Thanks for sharing the more complex example. Thanks to your example, I have just realized that I was mixing the block and the inline format which resulted to a string. The rule is that I have to use the inline format only:
|
As I explain in my thread I bump on the exact same issue (#41096). However, I fixed it for now with fix templates (for each environment) that I import as tasks in my main playbook. Kind regards, Yannick |
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
Templar
ANSIBLE VERSION
SUMMARY
This patch allows to use Jinja2 expressions in dictionary keys. Using this patch, the output of the following play
will result into this output:
instead of to this:
fixes #19956