From c377b904ad0e2839f5ae3dd611059a4d75a2d4bd Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Wed, 18 Oct 2023 19:04:46 +0200 Subject: [PATCH] Fix logic of discovering hosts by service For quite some time, we relate usage of --by-service flag for nova-manage cell_v2 discover_hosts command to the used nova_virt_type. However, we run db_post_setup tasks only once and delegating to the conductor host. With latest changes to the logic, when this task in included from the playbook level it makes even less sense, since definition of nova_virt_type for conductor is weird and wrong. Instead, we attempt to detect if ironic is in use by checking hostvars of all compute nodes for that. It will include host_vars, group_vars, all sort of extra variables, etc. Thus, ironic hosts should be better discovered now with nova-manage command. Related-Bug: #2034583 Change-Id: I3deea859a4017ff96919290ba50cb375c0f960ea (cherry picked from commit 4aa65eb60691c50c9022c22848e3338c8f350af3) --- defaults/main.yml | 1 + tasks/nova_db_post_setup.yml | 2 +- vars/main.yml | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 400810d7..e596ead1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -288,6 +288,7 @@ nova_console_type: "{{ (ansible_facts['architecture'] == 'aarch64') | ternary('s ## Nova ironic console # Set the console type. Presently the only options are ["serialconsole", "disabled"]. nova_ironic_console_type: "disabled" +nova_ironic_used: "{{ _nova_ironic_used }}" # Nova console ssl info, presently only used by novnc console type nova_console_ssl_dir: "/etc/nova/ssl" diff --git a/tasks/nova_db_post_setup.yml b/tasks/nova_db_post_setup.yml index c93cbd2a..175fc7c8 100644 --- a/tasks/nova_db_post_setup.yml +++ b/tasks/nova_db_post_setup.yml @@ -20,7 +20,7 @@ # This needs to be done after Compute hosts are added. - name: Perform a cell_v2 discover - command: "{{ _db_nova_bin }}/nova-manage cell_v2 discover_hosts{{ (debug | bool) | ternary(' --verbose', '') }}{{ (nova_virt_type == 'ironic') | ternary(' --by-service', '') }}" + command: "{{ _db_nova_bin }}/nova-manage cell_v2 discover_hosts{{ (debug | bool) | ternary(' --verbose', '') }}{{ (nova_ironic_used | bool) | ternary(' --by-service', '') }}" become: yes become_user: "{{ _db_nova_system_user_name }}" changed_when: false diff --git a/vars/main.yml b/vars/main.yml index 7ec1ded0..e2110bee 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -15,6 +15,15 @@ _nova_is_first_play_host: "{{ (nova_services['nova-conductor']['group'] in group_names and inventory_hostname == (groups[nova_services['nova-conductor']['group']] | intersect(ansible_play_hosts)) | first) | bool }}" +_nova_ironic_used: |- + {% set _virt_types = [] %} + {% for hv in groups[nova_services['nova-compute']['group']] %} + {% if 'nova_virt_type' in hostvars[hv] %} + {% set _ = _virt_types.append(hostvars[hv]['nova_virt_type']) %} + {% endif %} + {% endfor %} + {{ ('ironic' in _virt_types | unique) }} + nova_venv_packages: |- {%- set pkg_list = nova_pip_packages | union(nova_user_pip_packages) %} {%- if nova_oslomsg_amqp1_enabled | bool %}