From 67733c8f0cb13c467eb10f256a93d878c56d4743 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Tue, 6 Oct 2020 18:22:17 +0300 Subject: [PATCH] Define condition for the first play host one time We use the same condition, which defines against what host some "service" tasks should run against, several times. It's hard to keep it the same across the role and ansible spending additional resources to evaluate it each time, so it's simpler and better for the maintenance to set a boolean variable which will say for all tasks, that we want to run only against signle host, if they should run or not now. Depends-On: https://review.opendev.org/758953 Change-Id: Iab3194322e133282fcb71830f2b94e1279106ebd --- tasks/ironic_db_setup.yml | 3 +-- tasks/ironic_post_install.yml | 2 +- tasks/main.yml | 11 ++++------- vars/main.yml | 3 +++ 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tasks/ironic_db_setup.yml b/tasks/ironic_db_setup.yml index 7ee2d8fe..995812f9 100644 --- a/tasks/ironic_db_setup.yml +++ b/tasks/ironic_db_setup.yml @@ -25,5 +25,4 @@ become: yes changed_when: false when: - - ironic_services['ironic-inspector']['group'] in group_names - - inventory_hostname == groups[ironic_services['ironic-inspector']['group']][0] + - _ironic_inspector_is_first_play_host diff --git a/tasks/ironic_post_install.yml b/tasks/ironic_post_install.yml index 1971aff3..ea283bbf 100644 --- a/tasks/ironic_post_install.yml +++ b/tasks/ironic_post_install.yml @@ -25,7 +25,7 @@ OS_ENDPOINT_TYPE: internalURL when: - not ironic_enable_web_server_for_images | bool - - inventory_hostname == groups['ironic_all'][0] + - _ironic_api_is_first_play_host - not ironic_standalone | bool tags: - always diff --git a/tasks/main.yml b/tasks/main.yml index a850232b..8670d231 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -26,8 +26,7 @@ - import_tasks: db_setup.yml when: - - "ironic_services['ironic-api']['group'] in group_names" - - "inventory_hostname == ((groups[ironic_services['ironic-api']['group']]| intersect(ansible_play_hosts)) | list)[0]" + - _ironic_api_is_first_play_host vars: _oslodb_setup_host: "{{ ironic_db_setup_host }}" _oslodb_ansible_python_interpreter: "{{ ironic_db_setup_python_interpreter }}" @@ -44,8 +43,7 @@ - import_tasks: db_setup.yml when: - - "ironic_services['ironic-inspector']['group'] in group_names" - - "inventory_hostname == ((groups[ironic_services['ironic-inspector']['group']]| intersect(ansible_play_hosts)) | list)[0]" + - _ironic_inspector_is_first_play_host vars: _oslodb_setup_host: "{{ ironic_inspector_db_setup_host }}" _oslodb_ansible_python_interpreter: "{{ ironic_inspector_db_setup_python_interpreter }}" @@ -62,8 +60,7 @@ - import_tasks: mq_setup.yml when: - - "ironic_services['ironic-api']['group'] in group_names" - - "inventory_hostname == ((groups[ironic_services['ironic-api']['group']]| intersect(ansible_play_hosts)) | list)[0]" + - _ironic_api_is_first_play_host vars: _oslomsg_rpc_setup_host: "{{ ironic_oslomsg_rpc_setup_host }}" _oslomsg_rpc_userid: "{{ ironic_oslomsg_rpc_userid }}" @@ -153,7 +150,7 @@ _service_users: "{{ ironic_service_user_list }}" _service_endpoints: "{{ ironic_service_endpoint_list }}" _service_catalog: "{{ ironic_service_catalog_list }}" - when: (inventory_hostname == groups['ironic_api'][0] or inventory_hostname == groups['ironic_inspector'][0]) + when: (_ironic_api_is_first_play_host or _ironic_inspector_is_first_play_host) tags: - ironic-config diff --git a/vars/main.yml b/vars/main.yml index a04b26c5..3b4e47dd 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -13,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +_ironic_api_is_first_play_host: "{{ (ironic_services['ironic-api']['group'] in group_names and inventory_hostname == (groups[ironic_services['ironic-api']['group']] | intersect(ansible_play_hosts)) | first) | bool }}" +_ironic_inspector_is_first_play_host: "{{ (ironic_services['ironic-inspector']['group'] in group_names and inventory_hostname == (groups[ironic_services['ironic-inspector']['group']] | intersect(ansible_play_hosts)) | first) | bool }}" + # This special list brings together all of the package installations into one # task to save time.