That’s not right either. It’s super wasteful since newer versions of Ansible don’t magic loops into a single call to your package manager anymore. You have to pass the list as a single item.
- name: Install stuff.
package:
name: [git, httpd]Agreed, great callout for the example use case, my point was simply using the items list which could even be used for something like shell or win_shell
Note that it was possible to install multiple packages in one call by passing the whole list to yum/apt. This was undocumented but happened to work.
You just had to supply the list as space separated. i.e.
package: {{ packages|join(' ') }}
or similar
Re:Replacing Ansible with salt-ssh
by deeblering4 on Thursday October 22, 2020 @01:54PM
(#24860967)
Is this the case too with other resources, like users? I noticed that those loops can become pretty time consuming as the user list gets larger.
Re:Replacing Ansible with salt-ssh
by geerlingguy on Thursday October 22, 2020 @01:59PM
(#24861052)
It depends on the module; the user module works on one entity at a time, so you have to loop at the task level, which does take a little longer that trying to pass through a batch of user data at once.
The article uses with_list rather than with_items but even with with_items, that syntax would be working and define {{ item }} fine.
Please check the docs of with_list at https://docs.ansible.com/ansible/latest/user_guide/playbooks... .
Their point is not about how to pass in those parameters to the `package` task. They want to reuse the list of items as the value of the tags list, which they can't without duplicating the list.
Or they could define the list of packages as an array once? https://stackoverflow.com/questions/23507589/is-it-possible-...
Then just point the module to the array, like in the linked example.
edit; Check out Spivak's solution in the comments below. Interrogate the host and find out what is needed, then apply the install- saves you all the time of getting back 'ok' results.
https://www.educba.com/ansible-with_items/
Let me fix his code here: https://pastebin.com/PQDAnHiJ
I use with_items at least once a day in this manner.