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

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

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
  yum:
    name: "{{ item }}"
    state: 'present'
  with_items:
    - "{{ base_packages }}"
    - "{{ additional_packages | d(omit) }}"

Assuming base_packages and additional_packages are lists, try:

- name: install pkgs
  yum:
    state: present
    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

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]:

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