# yum module gives "AttributeError: 'list' object has no attribute 'strip'" on list of items

**URL:** <https://forum.ansible.com/t/yum-module-gives-attributeerror-list-object-has-no-attribute-strip-on-list-of-items/29998>\
**Category:** Ansible Project\
**Created:** [March 27, 2019, 4:16pm UTC](https://forum.ansible.com/t/yum-module-gives-attributeerror-list-object-has-no-attribute-strip-on-list-of-items/29998 "2019-03-27T16:16:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin\_Roevens](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Robin\_Roevens](https://forum.ansible.com/u/Robin_Roevens)\
**Post date:** [March 27, 2019, 4:16pm UTC](https://forum.ansible.com/t/yum-module-gives-attributeerror-list-object-has-no-attribute-strip-on-list-of-items/29998/1 "2019-03-27T16:16:42Z")

</div>

Hi all

I’m currently trying to get rid of all deprecation warnings as we upgraded Ansible 2.3 to 2.7.9 (CentOS 7.4)  
And I have this code:

- name: Install required system packages  
yum:  
name: “{{ item }}”  
state: ‘present’  
with\_items:
- “{{ base\_packages }}”
- “{{ additional\_packages | d(omit) }}”

Which triggers the warning:  
[DEPRECATION WARNING]: Invoking “yum” only once while using a loop via squash\_actions is deprecated. Instead of using a loop to supply multiple items and specifying `name: "{{ item }}"`, please use `name: ['{{ base_packages }}', '{{ additional_packages | d(omit) }}']` and remove the loop. This feature will be removed in version 2.11. Deprecation warnings can be disabled by setting deprecation\_warnings=False in ansible.cfg.

So I did exactly as I’m told and changed the yaml to:

- name: Install required system packages  
yum:  
name: [“{{ base\_packages }}”, “{{ additional\_packages | d(omit) }}”]  
state: ‘present’

However instead of the expected profit, I now get this error:  
fatal: [\*\***]: FAILED! =\> {“changed”: false, “module\_stderr”: “Shared connection to \*\*\*\*\*\*\*\* closed.\r\n”, “module\_stdout”: "Traceback (most recent call last):\r\n File "/home/ops/.ansible/tmp/ansible-tmp-1553701282.46-91084623823669/AnsiballZ\_yum.py", line 113, in \r\n \_ansiballz\_main()\r\n File "/home/ops/.ansible/tmp/ansible-tmp-1553701282.46-91084623823669/AnsiballZ\_yum.py", line 105, in \_ansiballz\_main\r\n invoke\_module(zipped\_mod, temp\_path, ANSIBALLZ\_PARAMS)\r\n File "/home/ops/.ansible/tmp/ansible-tmp-1553701282.46-91084623823669/AnsiballZ\_yum.py", line 48, in invoke\_module\r\n imp.load\_module(‘main’, mod, module, MOD\_DESC)\r\n File "/tmp/ansible\_yum\_payload\_PO7N0L/main.py", line 1571, in \r\n File "/tmp/ansible\_yum\_payload\_PO7N0L/main.py", line 1566, in main\r\n File "/tmp/ansible\_yum\_payload\_PO7N0L/main.py", line 375, in init\r\n File "/tmp/ansible\_yum\_payload\_PO7N0L/ansible\_yum\_payload.zip/ansible/module\_utils/yumdnf.py", line 79, in init\r\nAttributeError: ‘list’ object has no attribute ‘strip’**\r\n", “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}

I checked on the control machine, there are no old versions of the modules laying around. Also I tried using the package module, but that generates exactly the same error.  
Is this because, in this case, {{ additional\_packages }} is empty ? If so, how should I then handle this instead of d(omit) ?

Thanks!

Robin

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [March 27, 2019, 5:47pm UTC](https://forum.ansible.com/t/yum-module-gives-attributeerror-list-object-has-no-attribute-strip-on-list-of-items/29998/2 "2019-03-27T17:47:31Z")

</div>

Hi Robin,

> Hi all
> 
> I'm currently trying to get rid of all deprecation warnings as we upgraded  
> Ansible 2.3 to 2.7.9 (CentOS 7.4)  
> And I have this code:
> 
> - name: Install required system packages  
> &nbsp;&nbsp;yum:  
> &nbsp;&nbsp;&nbsp;&nbsp;name: "{{ item }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;state: 'present'  
> &nbsp;&nbsp;with\_items:  
> &nbsp;&nbsp;&nbsp;&nbsp;- "{{ base\_packages }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;- "{{ additional\_packages | d(omit) }}"

Assuming base\_packages and additional\_packages are lists, try:

- name: install pkgs  
&nbsp;&nbsp;yum:  
&nbsp;&nbsp;&nbsp;&nbsp;state: present  
&nbsp;&nbsp;&nbsp;&nbsp;name: "{{ base\_pkgs + additional\_pkgs | default() }}"

Ansible wants a flat list here. The suggestion in the deprecation  
warning thinks both are just normal values and wants you to put them  
into a list.

But if you already have lists, merge them with + as in the above code.

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![Robin\_Roevens](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Robin\_Roevens](https://forum.ansible.com/u/Robin_Roevens)\
**Post date:** [March 28, 2019, 11:57am UTC](https://forum.ansible.com/t/yum-module-gives-attributeerror-list-object-has-no-attribute-strip-on-list-of-items/29998/3 "2019-03-28T11:57:16Z")

</div>

Hi Sebastian

Merging the lists indeed did the trick. Thanks for the suggestion!

However, I have another, related question; The next task in this playbook is like this:

- name: Install extra packages required for plugins  
yum:  
name: “{{ item.packages }}”  
state: “present”  
with\_items:
- “{{ default\_plugins }}”
- “{{ plugins | d(omit) }}”  
when: item.packages is defined

And currently ansible even doesn’t give a deprecation warning on this task despite that I’m using a loop in combination with yum. And the only difference I see is that i’m using {{ item.packages }} instead of {{ item }} but I assume this will also deprecate ?  
How should I rewrite this then ?

Thanks

Robin

Sebastian Meyer schreef op wo 27-03-2019 om 18:47 [+0100]:

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [March 28, 2019, 12:07pm UTC](https://forum.ansible.com/t/yum-module-gives-attributeerror-list-object-has-no-attribute-strip-on-list-of-items/29998/4 "2019-03-28T12:07:19Z")

</div>

> Hi Sebastian  
> Merging the lists indeed did the trick. Thanks for the suggestion!  
> However, I have another, related question; The next task in this  
> playbook is like this:  
> - name: Install extra packages required for plugins yum: name:  
> "{{ item.packages }}" state: "present" with\_items: - "{{  
> default\_plugins }}" - "{{ plugins | d(omit) }}" when:  
> item.packages is defined  
> And currently ansible even doesn't give a deprecation warning on this

In my opinion, the depreciation warning should have never been added, as your task will never stop working. It was more like a feature notification that you can install multiple packages at once, which ansible does sometimes automatically. In your case here, ansible does not automatically install all the packages at once, so there's no warning that ansible will stop doing so in a future release. In any case your playbook will continue to have the same end result as it does today, with our without changes to squash this warning.

V/r,  
James Cassell
