You can definitely pass in with_items with a list of hashes.
module_name: foo={{ item.name }} bar={{ item.value }}
with_items:
- { name: 'x', value: 'y' }
- { name: 'a', value: 'b' }
etc
or with_items: alist_of_hashes
etc
or as you have it, with
with_items: [ { name: 'x', value: 'y' }, { name: 'a', value: 'b' } ]
It seems like in your question instead of
zfs: {{ item }}
you might need to pass something more specific?
zfs: {{ item.zfs }}
??
am I misunderstanding the question ?
On Tue, Dec 10, 2013 at 2:28 AM, Giorgio Valoti <[email protected]> wrote:
> Michael DeHaan <[email protected]> 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.
>
> --
> Giorgio Valoti
>
> --
> 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].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
Michael DeHaan <[email protected]>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/
--
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].
For more options, visit https://groups.google.com/groups/opt_out.