Skip certain items on condition in ansible with_items loop

Question:

Is it possible to skip some items in Ansible with_items loop operator, on a conditional, without generating an additional step?

Just for example:

in this task I want to create file 2 only when test_var is defined.

Answer:

The other answer is close but will skip all items != 2. I don’t think that’s what you want. here’s what I would do:

Leave a Reply