commit 7fffe91d5aec9d1b06bd2754c2a846bb7e6fefa5 Author: Dmitriy Rabotyagov Date: Fri Sep 25 18:35:18 2020 +0300 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/755484 Change-Id: If7f26c8020d4b02ab9e82dcb69a7ba91a3b5d145 diff --git a/defaults/main.yml b/defaults/main.yml index c8a23a3..78ee1a1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -243,3 +243,6 @@ trove_services: execstarts: "{{ trove_bin }}/trove-taskmanager" init_config_overrides: "{{ trove_taskmanager_init_config_overrides }}" start_order: 3 + +_trove_is_first_play_host: "{{ (trove_services['trove-api']['group'] in group_names and inventory_hostname == (groups[trove_services['trove-api']['group']] | intersect(ansible_play_hosts)) | first) | bool }}" +_trove_conductor_is_first_play_host: "{{ (trove_services['trove-conductor']['group'] in group_names and inventory_hostname == (groups[trove_services['trove-conductor']['group']] | intersect(ansible_play_hosts)) | first) | bool }}" diff --git a/tasks/main.yml b/tasks/main.yml index 1561e46..a03429c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -37,8 +37,7 @@ - import_tasks: db_setup.yml when: - - "trove_services['trove-api']['group'] in group_names" - - "inventory_hostname == ((groups[trove_services['trove-api']['group']]| intersect(ansible_play_hosts)) | list)[0]" + - _trove_is_first_play_host vars: _oslodb_setup_host: "{{ trove_db_setup_host }}" _oslodb_ansible_python_interpreter: "{{ trove_db_setup_python_interpreter }}" @@ -55,8 +54,7 @@ - import_tasks: mq_setup.yml when: - - "trove_services['trove-api']['group'] in group_names" - - "inventory_hostname == ((groups[trove_services['trove-api']['group']]| intersect(ansible_play_hosts)) | list)[0]" + - _trove_is_first_play_host vars: _oslomsg_rpc_setup_host: "{{ trove_oslomsg_rpc_setup_host }}" _oslomsg_rpc_userid: "{{ trove_oslomsg_rpc_userid }}" @@ -169,12 +167,12 @@ - name: "{{ trove_service_name }}" type: "{{ trove_service_type }}" description: "{{ trove_service_description }}" - when: inventory_hostname == groups['trove_api'][0] + when: _trove_is_first_play_host tags: - trove-install - import_tasks: trove_db_sync.yml - when: inventory_hostname == groups['trove_conductor'][0] + when: _trove_conductor_is_first_play_host tags: - trove-install