# Passing to a module a list of values

**URL:** <https://forum.ansible.com/t/passing-to-a-module-a-list-of-values/23842>\
**Category:** Ansible Project\
**Created:** [February 28, 2017, 1:09pm UTC](https://forum.ansible.com/t/passing-to-a-module-a-list-of-values/23842 "2017-02-28T13:09:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephane](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@stephane](https://forum.ansible.com/u/stephane)\
**Post date:** [February 28, 2017, 1:09pm UTC](https://forum.ansible.com/t/passing-to-a-module-a-list-of-values/23842/1 "2017-02-28T13:09:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 28, 2017, 1:29pm UTC](https://forum.ansible.com/t/passing-to-a-module-a-list-of-values/23842/2 "2017-02-28T13:29:53Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 28, 2017, 2:47pm UTC](https://forum.ansible.com/t/passing-to-a-module-a-list-of-values/23842/3 "2017-02-28T14:47:40Z")

</div>

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'.

---

<div class="post-metadata">

**Author:** ![stephane](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@stephane](https://forum.ansible.com/u/stephane)\
**Post date:** [February 28, 2017, 4:54pm UTC](https://forum.ansible.com/t/passing-to-a-module-a-list-of-values/23842/4 "2017-02-28T16:54:45Z")

</div>

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.
