Hi there,
I posted this to the Ansible Project list but got no responses, perhaps
this is the better forum for it to be answered though, so I'm cross posting
it here to.
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),
),
)
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 as desired:
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
--
You received this message because you are subscribed to the Google Groups
"Ansible Development" 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/d/optout.