I could not find any example in the official docs and other sources still use with_items which is deprciated. If anyone could point me to the correct documentation or reply with a possible solution, that would be wonderful.
with_items is not deprecated … its just that those writing the docs do not like to show more than one way to do things so they moved everything to use loop, which is the equivalent of with_list, with_ also has ‘magic’ which is sometimes hard to debug so the loop syntax is more explicit.
roles and import_role are run at ‘parse/compile time’ so they cannot support loops, that is what include_role is for, so it’s not ‘good practice’ but ‘only way to do it’.
And is the same as using import_role at task level:
tasks:
- name: some task
import_role:
name: some_role
I’m not sure why you can’t loop over items with static imports; something something pre-processed infos. TBH, I often forget about these limitation and switch conveniently between the two as needed.
Hope someone will clarify this point.
Long answer short, use include_role at task level, as you seem to have figured out already.
Hi @poinck! It looks like the post might be solved - could you check to see if any of the responses above worked for you?
If so, it would be super helpful if you could click the on their post to accept the solution - it recognises the input of others, helps our volunteers find new issues to answer, and keeps the forum nice and tidy.
Thanks!
(this is template reply, do feel free to reply if I’ve misunderstood the situation!)