Looping over inventory
Normally the play itself is a loop over your inventory, but sometimes you need a task to do the same over a different set of hosts.
To loop over your inventory, or just a subset of it, you can use a regularloopwith theansible_play_batchorgroupsvariables.
There is also a specific lookup plugininventory_hostnamesthat can be used like this
More information on the patterns can be found inPatterns: targeting hosts and groups.