Hi there,
I'm trying to create an ansible module to install packages using a custom package management system. I want it to function like the core yum module says it does when used in a loop, i.e. "Instead of calling the module with a single package each time through the loop, ansible calls the module once with all of the package names from the loop"
How would I replicate this in my own module?
I couldn't see anything special in the source for the yum module that would enable this behaviour.
I tried just specifying the input as type list, simplified below:
module = AnsibleModule(
argument_spec = dict(
name=dict(type="list", required=True),
),
supports_check_mode = True
)
cmd = [ 'pkg_agent', '-X', ','.join(module.params'name']) ]
rc, out, err = module.run_command(cmd)
But when I used my module in a playbook, it didn't work:
tasks:
- name: "Install packages"
pkg_install:
name: "{{ item }}"
become: True
with_items:
- 'common-tests'
- 'ops-libs'
Both the debug output and the resulting behaviour was it running the install on each package individually, and not bundling them together.
The expected result was that it would run `pkg_agent -X common-tests,ops-libs` but what in fact happened is it ran `pkg_agent -X common-tests` and then `pkg_agent -X ops-libs`
This was using Ansible 2.2 on Ubuntu
Any help in where I've gone wrong with this would be much appreciated.
- Peter