Skip to content

Commit

Permalink
Merge pull request #319 from reihl/create_virt_dict_with_modules
Browse files Browse the repository at this point in the history
Convert shell command to libvirt module
  • Loading branch information
ramperher authored Jul 1, 2024
2 parents 298e883 + dbd8558 commit a0b9a58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
32 changes: 23 additions & 9 deletions roles/ocp_on_libvirt/tasks/redfish_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,29 @@
sushy_ignore_boot_device: false
inventory_validated: true

- name: Get KVM hosts UUID
shell: >
set -o pipefail; virsh list --all --name --uuid |
sed -e 's/^\([^ ]*\) \([^ ]*\)$/"\2": "\1",/g' |
tr -d '\n' |
sed -e 's/^\(.*\),$/{\1}/g'
register: all_vms
- name: Get KVM host list
become: true
register: _ool_vms
community.libvirt.virt:
command: list_vms

- name: Get KVM hosts xml
become: true
register: _ool_vms_xml
loop: "{{ _ool_vms.list_vms }}"
community.libvirt.virt:
command: get_xml
name: "{{ item }}"

- name: Extract UUID from xmls
loop: "{{ range(0, _ool_vms.list_vms | length ,1) | list }}"
register: _ool_host_uuid
community.general.xml:
xmlstring: "{{ _ool_vms_xml.results[item].get_xml }}"
xpath: /domain/uuid
content: text

- name: Store KVM hosts UUID
set_fact:
redfish_kvm_uuid: "{{ all_vms.stdout | from_json }}"
loop: '{{ range(0, _ool_vms.list_vms | length ,1) | list }}'
ansible.builtin.set_fact:
ool_redfish_kvm_uuid: "{{ ool_redfish_kvm_uuid | default({}) | combine({ _ool_vms.list_vms[item]: _ool_host_uuid.results[item].matches[0].uuid }) }}"
4 changes: 2 additions & 2 deletions roles/ocp_on_libvirt/templates/hosts.j2
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ labels={"cluster.ocs.openshift.io/openshift-storage": ""}
[masters]
{% for key, value in ironic_nodes.items() -%}
{% if 'master' in key -%}
{{ key }} {{ "ansible_host=" + key + "." + ansible_fqdn if not do_dns_config|bool else "" }} name={{ key }} role=master ipmi_user={{ value.ipmi_user }} ipmi_password={{ value.ipmi_pass }} ipmi_address={{ value.ipmi_address }} ipmi_port={{ value.ipmi_port }} provision_mac={{ value.mac_address }} hardware_profile=default socket_console={{ enable_conserver }}{% if value.root_device_hint is defined %} root_device_hint={{ value.root_device_hint }}{% endif %}{% if value.root_device_hint_value is defined %} root_device_hint_value={{ value.root_device_hint_value }}{% endif %}{% if key in redfish_kvm_uuid | default({}) %} kvm_uuid={{ redfish_kvm_uuid[key] }} redfish_port={{ redfish_port }}{% endif %}
{{ key }} {{ "ansible_host=" + key + "." + ansible_fqdn if not do_dns_config|bool else "" }} name={{ key }} role=master ipmi_user={{ value.ipmi_user }} ipmi_password={{ value.ipmi_pass }} ipmi_address={{ value.ipmi_address }} ipmi_port={{ value.ipmi_port }} provision_mac={{ value.mac_address }} hardware_profile=default socket_console={{ enable_conserver }}{% if value.root_device_hint is defined %} root_device_hint={{ value.root_device_hint }}{% endif %}{% if value.root_device_hint_value is defined %} root_device_hint_value={{ value.root_device_hint_value }}{% endif %}{% if key in ool_redfish_kvm_uuid | default({}) %} kvm_uuid={{ ool_redfish_kvm_uuid[key] }} redfish_port={{ redfish_port }}{% endif %}
{% endif %}
{%- endfor %}

Expand All @@ -50,7 +50,7 @@ ansible_ssh_extra_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/n
[workers]
{% for key, value in ironic_nodes.items() -%}
{% if 'worker' in key -%}
{{ key }} {{ "ansible_host=" + key + "." + ansible_fqdn if not do_dns_config|bool else "" }} name={{ key }} role=worker ipmi_user={{ value.ipmi_user }} ipmi_password={{ value.ipmi_pass }} ipmi_address={{ value.ipmi_address }} ipmi_port={{ value.ipmi_port }} provision_mac={{ value.mac_address }} hardware_profile=unknown socket_console={{ enable_conserver }}{% if value.root_device_hint is defined %} root_device_hint={{ value.root_device_hint }}{% endif %}{% if value.root_device_hint_value is defined %} root_device_hint_value={{ value.root_device_hint_value }}{% endif %}{% if key in redfish_kvm_uuid | default({}) %} kvm_uuid={{ redfish_kvm_uuid[key] }} redfish_port={{ redfish_port }}{% endif %}
{{ key }} {{ "ansible_host=" + key + "." + ansible_fqdn if not do_dns_config|bool else "" }} name={{ key }} role=worker ipmi_user={{ value.ipmi_user }} ipmi_password={{ value.ipmi_pass }} ipmi_address={{ value.ipmi_address }} ipmi_port={{ value.ipmi_port }} provision_mac={{ value.mac_address }} hardware_profile=unknown socket_console={{ enable_conserver }}{% if value.root_device_hint is defined %} root_device_hint={{ value.root_device_hint }}{% endif %}{% if value.root_device_hint_value is defined %} root_device_hint_value={{ value.root_device_hint_value }}{% endif %}{% if key in ool_redfish_kvm_uuid | default({}) %} kvm_uuid={{ ool_redfish_kvm_uuid[key] }} redfish_port={{ redfish_port }}{% endif %}
{% endif %}
{%- endfor %}

Expand Down

0 comments on commit a0b9a58

Please sign in to comment.