Ansible register result of multiple commands

Question:

I was given a task to verify some routing entries for all Linux server and here is how I did it using an Ansible playbook

You can see I have to repeat same task for each routing entry and I believe I should be able to avoid this. I tried use with_items loop but got following error message

is there a way to register variable for each command and loop over them one by one ?

Answer:

Starting in Ansible 1.6.1, the results registered with multiple items are stored in result.results as an array. So you can use result.results[0].stdout and so on.

Testing playbook:

Result:

Leave a Reply