mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-29 23:49:09 +00:00
Allow variables to be passed in to template lookup plugin (#18662)
This allows a single template to be evaluated with different values in
the same task. For example, with a template like 'x:{{a}}', one could do
something like this:
- foo:
a: "{{ lookup('template', 'x.j2', template_vars=dict(a=foo[item])) }}"
b: "{{ lookup('template', 'x.j2', template_vars=dict(a=bar[item])) }}"
with_items:
- x
- y
…and "a" and "b" would expand to different strings based on what we
passed in to the template lookup.
This commit is contained in:
parent
517c91df18
commit
20b0716948
2 changed files with 12 additions and 4 deletions
|
|
@ -556,6 +556,9 @@ Here are some examples::
|
|||
|
||||
- debug: msg="{{ lookup('template', './some_template.j2') }} is a value from evaluation of this template"
|
||||
|
||||
# Since 2.4, you can pass in variables during evaluation
|
||||
- debug: msg="{{ lookup('template', './some_template.j2', template_vars=dict(x=42)) }} is evaluated with x=42"
|
||||
|
||||
- name: loading a json file from a template as a string
|
||||
debug: msg="{{ lookup('template', './some_json.json.j2', convert_data=False) }} is a value from evaluation of this template"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue