Skip to content

Commit 556924a

Browse files
Add the hypervisors to the inventory
For use cases like ShiftOnStack the deployment may need to tweak the hypervisor. We did not have a way to tell the deployment how to reach the hypervisor so this commit exposes the hypervisor Ansible instance to each host and creates a hypervisors group in the generated inventory.
1 parent c2e4f9f commit 556924a

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

roles/libvirt_manager/templates/all-inventory.yml.j2

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ virtual machines.
2020
ansible_ssh_common_args: "-o StrictHostKeyChecking=no -J {{ ansible_user | default(ansible_user_id) }}@{{ _hostname }}"
2121
{% endif %}
2222
{% endfor %}
23+
hypervisors:
24+
hosts:
25+
{% set _hypervisors = (
26+
( _cifmw_libvirt_manager_layout.vms.values() | selectattr('target', 'defined') | map(attribute='target') | list)
27+
+ [inventory_hostname] ) | unique %}
28+
{% for _hypervisor in _hypervisors %}
29+
{{ _hypervisor }}:
30+
{% if hostvars[_hypervisor]['ansible_host'] is defined %}
31+
{% set _hostname = hostvars[_hypervisor]['ansible_host'] %}
32+
ansible_host: "{{ _hostname }}"
33+
ansible_ssh_private_key_file: "~/.ssh/ssh_{{ _hostname }}"
34+
vars:
35+
{% endif %}
36+
{% endfor %}
2337
localhosts:
2438
hosts:
2539
localhost:

roles/libvirt_manager/templates/inventory.yml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
{% else %}
1515
ansible_ssh_private_key_file: ~/.ssh/id_cifw
1616
{% endif %}
17+
cifmw_hypervisor_host: "{{ _cifmw_libvirt_manager_layout.vms[host.key].target | default(inventory_hostname) }}"
1718
{% endfor %}

roles/reproducer/tasks/configure_controller.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
marker: "## {mark} {{ _ssh_host }}"
180180
block: |-
181181
Host {{ _ssh_host }} {{ hostvars[host]['inventory_hostname'] }}
182+
Hostname {{ _ssh_host }}
182183
IdentityFile ~/.ssh/ssh_{{ _ssh_host }}
183184
StrictHostKeyChecking no
184185
UserKnownHostsFile /dev/null

0 commit comments

Comments
 (0)