ansible_pkg_pgr and with_items

291 views
Skip to first unread message

Alexey Wasilyev

unread,
Feb 12, 2015, 11:59:22 AM2/12/15
to ansible...@googlegroups.com
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?

Giovanni Tirloni

unread,
Feb 12, 2015, 8:20:01 PM2/12/15
to ansible...@googlegroups.com


On Thu, 12 Feb 2015 08:59 -0800, Alexey Wasilyev <awas...@qubell.com>
wrote:
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

Alexey Wasilyev

unread,
Feb 13, 2015, 1:28:39 AM2/13/15
to ansible...@googlegroups.com
Why you use local_action?


Giovanni

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/FbuUeSEBfOw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1423790393.1069199.226914481.0C5A232F%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.

Alexey Wasilyev

unread,
Feb 13, 2015, 1:38:23 AM2/13/15
to ansible...@googlegroups.com
Another problem,
yum: name={{ item }} state=installed
with_items: [package1, package2]

install packages as yum install package1 package2
but your solution install packages as
yum install package1; yum install package2
that is rather slower. How this can be fixed?

Giovanni Tirloni

unread,
Feb 13, 2015, 3:09:21 AM2/13/15
to ansible...@googlegroups.com
On Fri, 13 Feb 2015 10:28 +0400, Alexey Wasilyev <awas...@qubell.com>
wrote:
> Why you use local_action?

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

Giovanni

Giovanni Tirloni

unread,
Feb 13, 2015, 3:18:24 AM2/13/15
to ansible...@googlegroups.com
On Fri, 13 Feb 2015 10:38 +0400, Alexey Wasilyev <awas...@qubell.com>
wrote:
> Another problem,
> yum: name={{ item }} state=installed
> with_items: [package1, package2]
>
> install packages as yum install package1 package2
> but your solution install packages as
> yum install package1; yum install package2
> that is rather slower. How this can be fixed?

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

Alexey Wasilyev

unread,
Feb 13, 2015, 3:40:59 AM2/13/15
to ansible...@googlegroups.com
Currently yum module successfully install multiple packages in one time, the problem is how to do it with action


Giovanni

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/FbuUeSEBfOw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Tomasz Kontusz

unread,
Feb 13, 2015, 3:43:53 AM2/13/15
to ansible...@googlegroups.com
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 <awas...@qubell.com> napisał:

--
Wysłane za pomocą K-9 Mail.

Giovanni Tirloni

unread,
Feb 13, 2015, 5:04:22 AM2/13/15
to ansible...@googlegroups.com
On Fri, 13 Feb 2015 12:40 +0400, Alexey Wasilyev <awas...@qubell.com>
wrote:
> Currently yum module successfully install multiple packages in one time,
> the problem is how to do it with action

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

Brian Coca

unread,
Feb 13, 2015, 8:21:48 AM2/13/15
to ansible...@googlegroups.com
the hack lets you run the yum modules just 1 time, but the module
internally processes a package at a time.


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages