From a9f5d9767242d617751a270db2f66cf98038c789 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Tue, 6 Oct 2020 18:14:34 +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. Change-Id: I78d44704a0224b2c73832a607e84ea8d9499f8c2 --- tasks/main.yml | 12 ++++-------- vars/main.yml | 2 ++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 75b287e3..40d11ddd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -71,8 +71,7 @@ - import_tasks: db_setup.yml when: - - "nova_services['nova-conductor']['group'] in group_names" - - "inventory_hostname == ((groups[nova_services['nova-conductor']['group']] | intersect(ansible_play_hosts)) | list)[0]" + - _nova_is_first_play_host vars: _oslodb_setup_host: "{{ nova_db_setup_host }}" _oslodb_ansible_python_interpreter: "{{ nova_db_setup_python_interpreter }}" @@ -97,8 +96,7 @@ - import_tasks: mq_setup.yml when: - - "nova_services['nova-conductor']['group'] in group_names" - - "inventory_hostname == ((groups[nova_services['nova-conductor']['group']] | intersect(ansible_play_hosts)) | list)[0]" + - _nova_is_first_play_host vars: _oslomsg_rpc_setup_host: "{{ nova_oslomsg_rpc_setup_host }}" _oslomsg_rpc_userid: "{{ nova_oslomsg_rpc_userid }}" @@ -172,15 +170,13 @@ type: "{{ nova_service_type }}" description: "{{ nova_service_description }}" when: - - "nova_services['nova-conductor']['group'] in group_names" - - "inventory_hostname == ((groups['nova_conductor'] | intersect(ansible_play_hosts)) | list)[0]" + - _nova_is_first_play_host tags: - nova-config - import_tasks: nova_db_setup.yml when: - - "nova_services['nova-conductor']['group'] in group_names" - - "inventory_hostname == ((groups['nova_conductor'] | intersect(ansible_play_hosts)) | list)[0]" + - _nova_is_first_play_host tags: - nova-config diff --git a/vars/main.yml b/vars/main.yml index fb6d4c6a..ee677634 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +_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_venv_packages: |- {%- set pkg_list = nova_pip_packages | union(nova_user_pip_packages) %} {%- if nova_oslomsg_amqp1_enabled | bool %}