From 353dc3d050bf22c0057b76d7208dd1a94c5798bc Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 25 Sep 2020 18:29:03 +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: I5c92722d5e7c49d0a01c7e9dbd0b254b5bea6dc4 --- tasks/main.yml | 8 ++++---- vars/main.yml | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 23aea3c..51ba752 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -29,7 +29,7 @@ - import_tasks: db_setup.yml when: - - inventory_hostname == groups['tacker_all'][0] + - _tacker_is_first_play_host vars: _oslodb_setup_host: "{{ tacker_db_setup_host }}" _oslodb_ansible_python_interpreter: "{{ tacker_db_setup_python_interpreter }}" @@ -46,7 +46,7 @@ - import_tasks: mq_setup.yml when: - - inventory_hostname == groups['tacker_all'][0] + - _tacker_is_first_play_host vars: _oslomsg_rpc_setup_host: "{{ tacker_oslomsg_rpc_setup_host }}" _oslomsg_rpc_userid: "{{ tacker_oslomsg_rpc_userid }}" @@ -114,7 +114,7 @@ - import_tasks: tacker_db_sync.yml when: - - inventory_hostname == groups['tacker_all'][0] + - _tacker_is_first_play_host tags: - tacker-install @@ -145,7 +145,7 @@ type: "{{ tacker_service_type }}" description: "{{ tacker_service_description }}" when: - - inventory_hostname == groups['tacker_all'][0] + - _tacker_is_first_play_host tags: - tacker-install diff --git a/vars/main.yml b/vars/main.yml index 35f370d..96d474d 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -15,3 +15,4 @@ # See the License for the specific language governing permissions and # limitations under the License. +_tacker_is_first_play_host: "{{ ('tacker_all' in group_names and inventory_hostname == (groups['tacker_all'] | intersect(ansible_play_hosts)) | first) | bool }}"