4 ms·
You lost me when you when the author failed to properly understand how to use {{ item }} by defining with_items: https://www.educba.com/ansible-with_items/ htt
by crmrc114 6y ago
You lost me when you when the author failed to properly understand how to use {{ item }} by defining with_items:
https://www.educba.com/ansible-with_items/ https://www.educba.com/ansible-with_items/
Let me fix his code here:
https://pastebin.com/PQDAnHiJ https://pastebin.com/PQDAnHiJ
I use with_items at least once a day in this manner.
- Spivak 6y agoThat’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]
- crmrc114 6y agoAgreed, 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
- deeblering4 6y agoIs 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.
- geerlingguy 6y agoIt 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.
- emmelaich 6y agoNote 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
- Arnavion 6y agoTheir 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.
- crmrc114 6y agoOr they could define the list of packages as an array once? https://stackoverflow.com/questions/23507589/is-it-possible-to-set-a-fact-of-an-array-in-ansible 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.
- spyc 6y agoThe 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_loops.html#with-list https://docs.ansible.com/ansible/latest/user_guide/playbooks... .