diff --git a/roles/libvirt_manager/templates/all-inventory.yml.j2 b/roles/libvirt_manager/templates/all-inventory.yml.j2 index 9b9d8499a7..04190a6364 100644 --- a/roles/libvirt_manager/templates/all-inventory.yml.j2 +++ b/roles/libvirt_manager/templates/all-inventory.yml.j2 @@ -20,6 +20,20 @@ virtual machines. ansible_ssh_common_args: "-o StrictHostKeyChecking=no -J {{ ansible_user | default(ansible_user_id) }}@{{ _hostname }}" {% endif %} {% endfor %} +hypervisors: + hosts: +{% set _hypervisors = ( + ( _cifmw_libvirt_manager_layout.vms.values() | selectattr('target', 'defined') | map(attribute='target') | list) + + [inventory_hostname] ) | unique %} +{% for _hypervisor in _hypervisors %} + {{ _hypervisor }}: +{% if hostvars[_hypervisor]['ansible_host'] is defined %} +{% set _hostname = hostvars[_hypervisor]['ansible_host'] %} + ansible_host: "{{ _hostname }}" + ansible_ssh_private_key_file: "~/.ssh/ssh_{{ _hostname }}" + vars: +{% endif %} +{% endfor %} localhosts: hosts: localhost: diff --git a/roles/libvirt_manager/templates/inventory.yml.j2 b/roles/libvirt_manager/templates/inventory.yml.j2 index 861155f5b7..17509fe351 100644 --- a/roles/libvirt_manager/templates/inventory.yml.j2 +++ b/roles/libvirt_manager/templates/inventory.yml.j2 @@ -14,4 +14,5 @@ {% else %} ansible_ssh_private_key_file: ~/.ssh/id_cifw {% endif %} + cifmw_hypervisor_host: "{{ _cifmw_libvirt_manager_layout.vms[host.key].target | default(inventory_hostname) }}" {% endfor %} diff --git a/roles/reproducer/tasks/configure_controller.yml b/roles/reproducer/tasks/configure_controller.yml index cc86bc3db6..71ad3e3958 100644 --- a/roles/reproducer/tasks/configure_controller.yml +++ b/roles/reproducer/tasks/configure_controller.yml @@ -179,6 +179,7 @@ marker: "## {mark} {{ _ssh_host }}" block: |- Host {{ _ssh_host }} {{ hostvars[host]['inventory_hostname'] }} + Hostname {{ _ssh_host }} IdentityFile ~/.ssh/ssh_{{ _ssh_host }} StrictHostKeyChecking no UserKnownHostsFile /dev/null