Register variables in with_items loop in Ansible playbook

Question:

I’ve got a dictionary with different names like

Now, I want to checkout repositories and afterwards build docker images only when the source has changed.
Since getting the source and building the image is the same for all items except the name I created the tasks with with_items: images
and try to register the result with:

and also tried

Then I tried the following condition

and

This always results in fatal: [piggy] => |changed expects a dictionary

So how can I properly save the results of the operations in variable names based on the list I iterate over?

Update: I would like to have something like that:

Answer:

So how can I properly save the results of the operations in variable names based on the list I iterate over?

You don’t need to. Variables registered for a task that has with_items have different format, they contain results for all items.

Leave a Reply