From aef1b1723adda87f66b644c1f4597efd43a32a43 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 25 Sep 2020 17:47:22 +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: Icf411ab2df0f6e937ce056b085fee97b89fe8361 --- tasks/main.yml | 8 ++++---- vars/main.yml | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index c94cb33e..326904ea 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -44,7 +44,7 @@ - import_tasks: db_setup.yml when: - - inventory_hostname == groups['octavia_all'][0] + - _octavia_is_first_play_host vars: _oslodb_setup_host: "{{ octavia_db_setup_host }}" _oslodb_ansible_python_interpreter: "{{ octavia_db_setup_python_interpreter }}" @@ -61,7 +61,7 @@ - import_tasks: mq_setup.yml when: - - inventory_hostname == groups['octavia_all'][0] + - _octavia_is_first_play_host vars: _oslomsg_rpc_setup_host: "{{ octavia_oslomsg_rpc_setup_host }}" _oslomsg_rpc_userid: "{{ octavia_oslomsg_rpc_userid }}" @@ -161,7 +161,7 @@ - name: "{{ octavia_service_name }}" type: "{{ octavia_service_type }}" description: "{{ octavia_service_description }}" - when: inventory_hostname == groups['octavia_all'][0] + when: _octavia_is_first_play_host tags: - octavia-install @@ -192,7 +192,7 @@ - import_tasks: octavia_db_sync.yml when: - - inventory_hostname == groups['octavia_all'][0] + - _octavia_is_first_play_host tags: - octavia-install diff --git a/vars/main.yml b/vars/main.yml index 73555917..06a64069 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. +_octavia_is_first_play_host: "{{ (octavia_services['octavia-api']['group'] in group_names and inventory_hostname == (groups[octavia_services['octavia-api']['group']] | intersect(ansible_play_hosts)) | first) | bool }}" + # # Compile a list of the services on a host based on whether # the host is in the host group and the service is enabled.