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

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 \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}

Hi,

if I`m looking right, it can be indentation problem,

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

Hi David,

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

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

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

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 \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}

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).

Hi Brian,

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

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.

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

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

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

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 :wink: then you should
be able to rm -rf /usr/share/ansible.bak

-Toshio

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