Passing to a module a list of values

385 views
Skip to first unread message

step...@dupille.org

unread,
Feb 28, 2017, 8:09:56 AM2/28/17
to Ansible Project
Hello,

I'm currently trying to create a module to manage poudriere (which is a tool to manage package repository for FreeBSD).

When I use the pkgng module this way, the command pkgng is actually called once, and the "name" argument is a list of all values contained in the list provided :
- name: sample pkgng
  pkgng: name="{{item}}" state=present
  with_items: [ a, b, c]

But, when I call my poudriere module :
- name: sample poudriere
  poudriere: name="{{item}}" jail=jailname
  with_items: [ a, b, c]
the module is called three times, once per item value.

I assumed that to get the module called only once, all I had to do is to declare the "name" argument as of type 'list', but this is not working :
module = AnsibleModule(
  argument_spec = dict(
    name = dict(required=True, type='list'),
    jail = dict(required=True),
  ),
  supports_check_mode = True,
)

In my module, module.params['name'] is actually a list, but it contains a single value each time.

What am I missing ?

Thanks,
SD

J Hawkesworth

unread,
Feb 28, 2017, 8:29:54 AM2/28/17
to Ansible Project
Hi,

Some  modules (I think the yum module is one example) have a code optimization which allows them to handle a list passed to them in one go, rather than in multiple invocations of the code.

I suggest you have a look at the code for the yum module http://docs.ansible.com/ansible/yum_module.html
I haven't looked myself but there may also be an action plugin for yum to support this optimization.

Hope this helps,

Jon

Brian Coca

unread,
Feb 28, 2017, 9:47:47 AM2/28/17
to Ansible Project
If you are passing the list directly to name= it should 'just work',
if you are passing it through with_ ... your module needs to be
configured in squash_actions configuration. Be aware that we are
considering removing this 'magic'.


----------
Brian Coca

step...@dupille.org

unread,
Feb 28, 2017, 11:54:45 AM2/28/17
to Ansible Project
Hello !

It was the "squash_action" I was missing. Thanks a lot!

But passing a list directly to the name= is a good idea. I'll try that.

Reply all
Reply to author
Forward
0 new messages