# ansible\_pkg\_pgr and with\_items

**URL:** <https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508>\
**Category:** Ansible Project\
**Created:** [February 12, 2015, 4:59pm UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508 "2015-02-12T16:59:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey\_Wasilyev1](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@Alexey\_Wasilyev1](https://forum.ansible.com/u/Alexey_Wasilyev1)\
**Post date:** [February 12, 2015, 4:59pm UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/1 "2015-02-12T16:59:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 13, 2015, 1:19am UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/2 "2015-02-13T01:19:53Z")

</div>

Some valid ways to declare this:

&nbsp;&nbsp;&nbsp;&nbsp;- name: install packages  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local\_action: "{{ ansible\_pkg\_mgr }} name={{ item }} state=latest"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- lsof  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- nmap

&nbsp;&nbsp;&nbsp;&nbsp;- name: install packages  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local\_action: "{{ ansible\_pkg\_mgr }} name={{ item }} state=latest"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: [lsof, nmap]

&nbsp;&nbsp;&nbsp;&nbsp;- name: install packages  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local\_action: \>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ ansible\_pkg\_mgr }} name={{ item }} state=latest  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Alexey\_Wasilyev1](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@Alexey\_Wasilyev1](https://forum.ansible.com/u/Alexey_Wasilyev1)\
**Post date:** [February 13, 2015, 6:28am UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/3 "2015-02-13T06:28:34Z")

</div>

Why you use local\_action?

---

<div class="post-metadata">

**Author:** ![Alexey\_Wasilyev1](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@Alexey\_Wasilyev1](https://forum.ansible.com/u/Alexey_Wasilyev1)\
**Post date:** [February 13, 2015, 6:38am UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/4 "2015-02-13T06:38:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 13, 2015, 8:09am UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/5 "2015-02-13T08:09:12Z")

</div>

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

Giovanni

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 13, 2015, 8:18am UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/6 "2015-02-13T08:18:15Z")

</div>

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](http://bit.ly/1ClYXgl)

Giovanni

---

<div class="post-metadata">

**Author:** ![Alexey\_Wasilyev1](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@Alexey\_Wasilyev1](https://forum.ansible.com/u/Alexey_Wasilyev1)\
**Post date:** [February 13, 2015, 8:40am UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/7 "2015-02-13T08:40:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [February 13, 2015, 8:43am UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/8 "2015-02-13T08:43:23Z")

</div>

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](mailto:awasilyev@qubell.com) napisał:

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 13, 2015, 10:04am UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/9 "2015-02-13T10:04:16Z")

</div>

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

---

<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 13, 2015, 1:21pm UTC](https://forum.ansible.com/t/ansible-pkg-pgr-and-with-items/17508/10 "2015-02-13T13:21:45Z")

</div>

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