diff --git a/roles/ocp_on_libvirt/tasks/redfish_setup.yml b/roles/ocp_on_libvirt/tasks/redfish_setup.yml index f5ecc9eb2..91753260a 100644 --- a/roles/ocp_on_libvirt/tasks/redfish_setup.yml +++ b/roles/ocp_on_libvirt/tasks/redfish_setup.yml @@ -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 }) }}" diff --git a/roles/ocp_on_libvirt/templates/hosts.j2 b/roles/ocp_on_libvirt/templates/hosts.j2 index 0e9af9066..73fc21892 100644 --- a/roles/ocp_on_libvirt/templates/hosts.j2 +++ b/roles/ocp_on_libvirt/templates/hosts.j2 @@ -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 %} @@ -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 %}