register works a bit differently when used inside loops (see here ). In this case, your variable will have a results element, which is a list with the result of each iteration as elements. Each item in this list will also have an item , with the item repeating itself.
For instance:
mac: { msg: "All items completed", results: [ { changed: True, stdout: "some_stdout", item: { name: "some_name1" } }, { changed: True, stdout: "some_stdout2", item: { name: "some_name2" } } ] }
Then you can iterate over this instead of the original list:
- name: Setting MAC lineinfile: state=present dest=/etc/sysconfig/network-scripts/ifcfg-{{item.item.name}} regexp='^HWADDR=.*' line="HWADDR={{item.stdout}}" with_items: mac.results tags: - set_mac
source share