Michael DeHaan <michael@ansibleworks.com> writes:
In the argument_spec of the module that defines the argument, just do
type='dict'
It will accept complex arguments as well as quoted key=value pairs.
module_name:
foo:
x: 1
y: "bar"
baz: "glorp"
Is how complex args are passed
Or
module_name: 'foo="x=1 y=bar" baz="glorp"'
This is exactly how the ec2 module in 1.4/1.5 processes and passes instance
tags, if you want to take a look.
It also knows how to parse inline JSON, so it is very much a "do what you
mean" kind of input.
It works perfectly with a single item:
zfs:
state: present
name: ...
...
user_properties:
k: v
...
But I can’t find a way to iterate over it. Ideally, I’d like to write
something like:
zfs: {{ item }}
with_items: [{name: 'x', state: 'present', user_properties: {...}},
{name: 'y', state: 'present', mountpoint: '/path/to/mnt', ...} ]
When the property keys are variable but properties are all strings I can
write something like this:
module_name: state={{ item.state }}
name={{ item.name }}
{{ 'prop=%s' % item.prop if item.prop is defined else '' }}
...
I don’t like it, it’s verbose, and there’s probably a better way to do
it, but it works, if only with simple properties.
So my question becames how to iterate over a list of dictionaries,
possibily nested, with different keys?
Thanks a lot.