Ansible: "apt" module and loops
After upgrading Ansible to version 2.8.3, the "apt" module started spitting out deprecation warnings:
TASK [common : basic packages] ***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
[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: ['vim', 'screen', 'rsync']` 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.
ok: [hostname] => (item=['vim', 'screen', 'rsync'])
The cause of the warning is the following task (or other similar "apt" tasks):
- name: basic packages
apt:
name: "{{ item }}"
state: present
loop:
- vim
- screen
- rsync
Apparently the apt module is invoked for every item in the loop, and that is slow, and expensive.
There is a better way to do this:
- name: basic packages
apt:
name:
- vim
- screen
- rsync
state: present
But I yet have to figure out how to do this if the package names are in a variable. That is for another day ...
Comments
Display comments as Linear | Threaded