I have a list of strings strs = [ 'foo', 'bar' ] and some dicts foo = {'a': 1, 'b': 2}, bar = {'a': 3, 'b': 4}. I'd like to use with_items to index into the named dicts
- copy
src: {{item}}.a
dest: {{item}}.b
with_items: strs
But I want {{item}} to refer to the variables named foo and bar rather than the strings. In lisp or python I'd use eval for this. Is there something similar in ansible?
Why not set a dictionary and loop through it using with_dict?
---
- hosts: localhost
connection: local
vars:
strs:
foo:
a: 1
b: 2
bar:
a: 3
b: 4
tasks:
- copy: src={{ item.value.a }} dest={{ item.value.b }}
with_dict: strs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With