Ansible 2.7 Deprecation Warning – apt and squash_actions

DevOps ToolChain, WikiPedia, CC BY-SA 4.0
| | 0 Comments| 10:46 AM
Categories:

Ansible 2.7 was released recently and along with it brought a new deprecation warning for the apt module:

[code lang=text]
TASK [Install base packages] ******************************************
Thursday 18 October 2018 15:35:52 +0000 (0:00:01.648) 0:06:25.667 ******
[DEPRECATION WARNING]: Invoking "apt" 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: [u'htop', u'zsh', u's3cmd'] 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.
[/code]

Our apt task was:

[code lang=text]
– name: Install base packages
apt:
name: "{{ item }}"
state: present
update_cache: yes
with_items:
– htop
– zsh
– s3cmd
[/code]

Very standard.

The new style with Ansible 2.7 should look like:

[code lang=text]
– name: Install base packages
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
– htop
– zsh
– s3cmd
[/code]

The change is self-explanatory (and is alluded to in the deprecation warning): rather than loop over a list and applying the apt module, provide the module with a list of items to process.

You can read up on the documentation for apt in Ansible 2.7 here.

Leave a Reply

Your email address will not be published. Required fields are marked *