The following works for me. I changed a few things to be more yaml like, but I
think the heart of your issue was the way you were referencing the nested data:
vars:
git_merge_tool: meld
merge_tools:
meld:
path: '/usr/local/opt/meld/bin/meld'
tasks:
- debug:
msg: "{{ merge_tools[git_merge_tool]['path'] }}"
You were using:
merge_tools[git_merge_tool['path']]
I believe you had one of you ] chars in the wrong place. It should have come
immediately after 'git_merge_tool' rather than at the very end.
It should have been:
merge_tools[git_merge_tool]['path']
--
Matt Martz
[email protected]
On January 23, 2014 at 11:14:10 AM, kesten broughton
([email protected]) wrote:
What is the proper way to express f(g(const)) where f and g are variables in
task files?
Example:
vars:
git_merge_tool: meld
merge_tools: { 'meld': { 'path': '/usr/local/opt/meld/bin/meld' },
<other tools> }
tasks:
# I tried this
- name: Create symlinks to the git tools
file: state=link src="{{item.src}}" dest="{{item.dest}}"
- { src: "/usr/local/bin/{{git_merge_tool}}",
dest: "{{merge_tools[git_merge_tool['path']]}}" } <- this is
the problem
fatal: [ansible-os1] => One or more undefined variables: dict object has no
element Undefined
# And this
- { src: "/usr/local/bin/{{git_merge_tool}}",
dest: "{{merge_tools[{{git_merge_tool}}['path']]}}" }
NO ERROR: but creates a link to the string
{{merge_tools[git_merge_tool['path']]}}
# And even this
- { src: "/usr/local/bin/{{git_merge_tool}}",
dest: "{{merge_tools | attr(git_merge_tool) | attr('path') }}" }
TASK: [git | Create symlinks to the git tools] ********************************
fatal: [ansible-os1] => One or more undefined variables: 'dict object' has no
attribute 'meld'
Are nested vars supported in ansible task files?
kesten
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.