Ansible: how to call module `add_host` for all hosts of the play
As you noted, there's a thing about add_host
: BYPASS_HOST_LOOP = True
.
So it's a kind of forced run_once
.
If you don't mind running over hypervisors
in sequential manner, you can simply use serial: 1
:
- hosts: hypervisors
serial: 1
tasks:
- shell: virsh list | awk 'NR>2' | awk '{print $2}'
register: result_virsh
- add_host:
name: "{{ item }}"
group: "guests"
with_items: "{{ result_virsh.stdout_lines }}"
This ensures that every play batch consists of only one host, so add_host
executes for every host.