Attempting to yum install multiple packages using with_items results in Python AttributeError: 'list' object has no attribute 'split'

1751 views
Skip to first unread message

Joanna Delaporte

unread,
Nov 25, 2015, 12:40:08 PM11/25/15
to Ansible Project
Good afternoon, I am attempting to install multiple packages on a CentOS 7 server. I am using 2.0.0-rc1. I keep running into a python error.

I tried using a yum task in a role, using with_items like so:

- yum: name={{ item }} state=present
  with_items:
  - ypbind
  - rpcbind

I think that is the way it should be done, based on documentation. 
However, I keep getting this error: 

failed: [HOSTNAME] => (item=[u'ypbind', u'rpcbind']) => {"failed": true, "item": ["ypbind", "rpcbind"], "msg": "Traceback (most recent call last):\r\n  File \"/tmp/.ansible/ansible-tmp-1448471787.66-61112899447177/yum\", line 2744, in <module>\r\n    main()\r\n  File \"/tmp/.ansible/ansible-tmp-1448471787.66-61112899447177/yum\", line 833, in main\r\n    disablerepo, disable_gpg_check)\r\n  File \"/tmp/.ansible/ansible-tmp-1448471787.66-61112899447177/yum\", line 718, in ensure\r\n    items = pkgspec.split(',')\r\nAttributeError: 'list' object has no attribute 'split'\r\n", "parsed": false}



David Karban

unread,
Nov 25, 2015, 12:46:27 PM11/25/15
to ansible...@googlegroups.com
Hi,

if I`m looking right, it can be indentation problem,
- yum: name={{ item }} state=present
  with_items:
    - ypbind
    - rpcbind


David Karban
Linux server specialist/Specialista na správu linuxových serverů
www.karban.eu

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, 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/f26bb034-7cfa-48e6-b28a-e3e98551063d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joanna Delaporte

unread,
Nov 25, 2015, 2:00:42 PM11/25/15
to Ansible Project
Hi David, 

Thanks. I also tried it with more indentation, with the same error result:

- yum: pkg={{ item }} state=present
  with_items:
    - ypbind
    - rpcbind


Joanna Delaporte

unread,
Nov 25, 2015, 2:26:13 PM11/25/15
to Ansible Project
I have also tried the following dictionary layouts, which resulted in the same 'list object' python error:

- yum:
    name: "{{ item }}"
    state: present
  with_items:
  - ypbind
  - rpcbind

And this:

- yum:
    name:
    - ypbind
    - rpcbind
    state: present

Running the task with only one item works (both of the following succeeded):
- yum:
    name=ypbind state=present

- yum:
    name: rpcbind
    state: present

Joanna Delaporte

unread,
Nov 25, 2015, 2:32:01 PM11/25/15
to Ansible Project
Okay, so the yum module might actually be broken, because when I replaced "yum" with "package", it started working correctly. 

This works:
- package: name="{{ item }}" state=present
  with_items:
    - ypbind
    - rpcbind

This doesn't:
- yum: name="{{ item }}" state=present
  with_items:
    - ypbind
    - rpcbind

And fails with this error:
failed: [HOSTNAME] => (item=[u'ypbind', u'rpcbind']) => {"failed": true, "item": ["ypbind", "rpcbind"], "msg": "Traceback (most recent call last):\r\n  File \"/tmp/.ansible/ansible-tmp-1448479744.44-240902329915911/yum\", line 2742, in <module>\r\n    main()\r\n  File \"/tmp/.ansible/ansible-tmp-1448479744.44-240902329915911/yum\", line 831, in main\r\n    disablerepo, disable_gpg_check)\r\n  File \"/tmp/.ansible/ansible-tmp-1448479744.44-240902329915911/yum\", line 716, in ensure\r\n    items = pkgspec.split(',')\r\nAttributeError: 'list' object has no attribute 'split'\r\n", "parsed": false}


On Wednesday, November 25, 2015 at 1:00:42 PM UTC-6, Joanna Delaporte wrote:

Brian Coca

unread,
Nov 25, 2015, 2:53:46 PM11/25/15
to Ansible Project
package will just call yum module, the main difference is in the
'squashing', another check you can do to confirm this is set the env
var ANSIBLE_SQUASH_ACTIONS="apt,pkgng", which would avoid that in yum
(which is part of default list).


--
Brian Coca

Joanna Delaporte

unread,
Nov 25, 2015, 7:09:27 PM11/25/15
to ansible...@googlegroups.com

Hi Brian,

Okay, but why does my play work with package, but not yum?

--
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/CPSejzrgW18/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.

Brian Coca

unread,
Nov 25, 2015, 7:10:42 PM11/25/15
to Ansible Project
if you run the test i asked, i can confirm it will be because of
argument squashing, which is an optimization that will run on yum but
not on package.

--
Brian Coca

Joanna Delaporte

unread,
Nov 25, 2015, 7:22:16 PM11/25/15
to ansible...@googlegroups.com

Yes, right. Sorry for my misunderstanding. I'll get back to you with a test run after I feed my kids dinner.

--
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/CPSejzrgW18/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.

Joanna Delaporte

unread,
Nov 25, 2015, 7:44:51 PM11/25/15
to Ansible Project
Alright, it worked with that variable you requested. 

I exported the env var (it didn't work just set in the current shell):
export ANSIBLE_SQUASH_ACTIONS="apt,pkgng"

And ran this play:
- yum: name="{{ item }}" state=present
  with_items:
    - ypbind
    - rpcbind

The play succeeded with this variable set.

Thanks!
Joanna

Toshio Kuratomi

unread,
Nov 25, 2015, 8:04:33 PM11/25/15
to ansible...@googlegroups.com
From the traceback you showed in your original message, it looks like
somehow you have an old version of the yum module being used with the
current rc1 for /usr/bin/ansible-playbook. items = pkgspec.split(',')
from the traceback message is no longer present in the yum module.
Perhaps there's some old version of ansible present on the machine and
its yum module is overriding the one from rc1 or you have the
ANSIBLE_LIBRARY environment variable set to some path where an
alternative yum module is living.

-Toshio
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, 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/eb34144b-5b58-4ce2-b8b9-ef02b71d760b%40googlegroups.com.

Joanna Delaporte

unread,
Nov 25, 2015, 8:19:27 PM11/25/15
to Ansible Project
Hi Toshio,

ANSIBLE_LIBRARY is unset. 

$ ansible --version
ansible 2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = /usr/share/ansible

With a little investigation, I see the long listing of /usr/share/ansible/packaging shows all files with a date of April 2014, even though one level up they are all dated 11/23/15. 

A couple days ago, I did an untar, make, make install of the package. Today, I attempted to reinstall pip because I was having these issues:

And just now I did a pip force reinstall:

The module files are still all the old ones from April 2014. How do I get the updated module files? 

Toshio Kuratomi

unread,
Nov 25, 2015, 9:55:43 PM11/25/15
to ansible...@googlegroups.com
On Wed, Nov 25, 2015 at 5:19 PM, Joanna Delaporte
<joannad...@gmail.com> wrote:
> Hi Toshio,
>
> ANSIBLE_LIBRARY is unset.
>
> $ ansible --version
> ansible 2.0.0
> config file = /etc/ansible/ansible.cfg
> configured module search path = /usr/share/ansible
>
> With a little investigation, I see the long listing of
> /usr/share/ansible/packaging shows all files with a date of April 2014, even
> though one level up they are all dated 11/23/15.
>
> A couple days ago, I did an untar, make, make install of the package. Today,
> I attempted to reinstall pip because I was having these issues:
> pip install --upgrade
> http://releases.ansible.com/ansible/ansible-2.0.0-0.6.rc1.tar.gz
>
> And just now I did a pip force reinstall:
> # pip install --force-reinstall
> http://releases.ansible.com/ansible/ansible-2.0.0-0.6.rc1.tar.gz
>
> The module files are still all the old ones from April 2014. How do I get
> the updated module files?
>
The modules are now installed in the ansible library directory
(something like /usr/lib/python2.7/site-packages/ansible/ ... varies a
little bit depending on the distribution that you are running). The
files in /usr/share/ansible are likely from an old install. I'd try
this:

$ sudo mv /usr/share/ansible /usr/share/ansible.bak

If you can then run your playbook/ansible commands and it still finds
its modules (hopefully now the up-to-date modules ;-) then you should
be able to rm -rf /usr/share/ansible.bak

-Toshio

Joanna Delaporte

unread,
Nov 25, 2015, 11:16:50 PM11/25/15
to Ansible Project
Thanks! I found the paths on my machines so I could set them in my ansible.cfg file. I appreciate the tip!

For reference, I found the modules dirs in these two locations on my current control hosts:
/usr/local/lib/python2.7/dist-packages/ansible/modules (Ubuntu 14.04)
/usr/lib64/python2.7/site-packages/ansible/modules (Slackware 14.1)

This will probably fix several errors I have been trying to work around, mostly related to lists breaking, in 2.0.

Thanks!
Joanna
Reply all
Reply to author
Forward
0 new messages