ansible_pkg_pgr and with_items

Hello, everybody.

Can somebody show me the working example of following code?

  • name: ‘Install packages’
    action: >
    {{ ansible_pkg_mgr }} name={{ item }} state=installed
    with_items: [package1, package2]

Without with_items - its worked. When I specify yum/apt instead {{ ansible_pkg_mgr }} - it’s worked.
How I can combine with_items and {{ ansible_pkg_mgr }} together?

Some valid ways to declare this:

    - name: install packages
      local_action: "{{ ansible_pkg_mgr }} name={{ item }} state=latest"
      with_items:
        - lsof
        - nmap

    - name: install packages
      local_action: "{{ ansible_pkg_mgr }} name={{ item }} state=latest"
      with_items: [ lsof, nmap ]

    - name: install packages
      local_action: >
        {{ ansible_pkg_mgr }} name={{ item }} state=latest
      with_items: [ lsof, nmap ]

Generally I try to use YAML only and avoid Ansible's syntax (with equal
signs). However, with free-form arguments, it's hard to avoid it. IMHO,
it's too much flexibility and backward compatibility, but that's because
I don't have a "legacy" code base to worry about.

Giovanni

Why you use local_action?

Another problem,
yum: name={{ item }} state=installed
with_items: [package1, package2]

I probably misread your initial email, sorry. Just tested and the
behavior is the same with 'action'.

Giovanni

It's designed to work on one package at a time. IMHO, working on
multiple packages simultaneously will complicate the module because now
it has to parse yum's output and understand it, instead of just relying
on yum's return code.

You could use the shell/command modules, but they will warn you to use
the yum module instead ("Consider using yum module rather than running
yum"). In fact, it'll warn you about using any of the commands listed
here: http://bit.ly/1ClYXgl

Giovanni

Currently yum module successfully install multiple packages in one time, the problem is how to do it with action

There’s a hack in Ansible that turns with_items + yum/apt into name={{ packages_to_install | join (“,”) }}, so:

action: “{{ ansible_pkg_mgr }} name={{ [‘package1’, ‘package2’] | join (”,“) }}”

Alexey Wasilyev awasilyev@qubell.com napisał:

At least with Ansible 1.8.2, I don't see this happening with the yum
module (and multiple package in with_items).

I'm curious how this can be achieved without the hack Tomasz mentioned.

Giovanni

the hack lets you run the yum modules just 1 time, but the module
internally processes a package at a time.