Item name in task name.

31 views
Skip to first unread message

Varun Chopra

unread,
Jan 29, 2018, 11:02:58 AM1/29/18
to Ansible Project
Hi,

I'm trying to display the item name in the name of the task but it doesn't work as intended.

Here's part of my play:

  tasks:
    - name: Installing {{ item }}
      yum:
        name: "{{ item }}"
        state: latest
      with_items:
        - httpd
        - firewalld

This is what I get when I run the play:

TASK [Installing {{ item }}] ******************************************************************************************
ok: [servera.example.com] => (item=[u'httpd', u'firewalld'])


Is this supposed to work this way? I

ZillaYT

unread,
Jan 31, 2018, 3:07:49 PM1/31/18
to Ansible Project
Try enclosing the name in double-quotes, e.g.,

  tasks:
   
- name: "Installing {{ item }}"
      yum
:
        name
: "{{ item }}"
        state
: latest
      with_items
:
       
- httpd
       
- firewalld


Malcolm Hussain-Gambles

unread,
Jan 31, 2018, 5:26:32 PM1/31/18
to Ansible Project
I don't think you can do that, as the item isn't defined when it prints the name section. I also seem to remember that certain modules,like yum will process the list in one go. Rather than doing two yum installs.

Varun Chopra

unread,
Feb 1, 2018, 10:10:02 AM2/1/18
to Ansible Project
This doesn't matter.

Varun Chopra

unread,
Feb 1, 2018, 10:10:28 AM2/1/18
to Ansible Project
Yeah, you're right!

Thanks!

Kai Stian Olstad

unread,
Feb 1, 2018, 10:22:01 AM2/1/18
to ansible...@googlegroups.com
On Thursday, 1 February 2018 16.10.27 CET Varun Chopra wrote:
> Yeah, you're right!

There is a workaround to get if you want it, it involves include_tasks.

file-to-include.yml
---
- name: Installing {{ item }}
yum:
name: "{{ item }}"
state: latest



tasks:
- include_tasks: file-to-include.yml
with_items:
- httpd
- firewalld


But this will be a bit slower since you are running yum one by one for each item.
When you have with_items on the yum task it will install all of them in one yum command.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages