Skip to content

Commit

Permalink
Add the hypervisors to the inventory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pablintino committed Dec 20, 2024
1 parent fc30400 commit 8462e7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions roles/libvirt_manager/templates/all-inventory.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ 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 }}:
{% set _hostname = hostvars[_hypervisor]['ansible_host'] | default(_hypervisor[_target]['inventory_hostname']) %}
ansible_host: "{{ _hostname }}"
ansible_ssh_private_key_file: "~/.ssh/ssh_{{ _hostname }}"
vars:
{% endfor %}
localhosts:
hosts:
localhost:
Expand Down
1 change: 1 addition & 0 deletions roles/libvirt_manager/templates/inventory.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
1 change: 1 addition & 0 deletions roles/reproducer/tasks/configure_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8462e7d

Please sign in to comment.