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