commit a969b5ee7742d28c77df48bd89999c675bbe839a Author: Dmitriy Rabotyagov Date: Fri Sep 11 15:00:25 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. Change-Id: I6f1937c329292028e772fbe96d2466000726e4b7 diff --git a/tasks/main.yml b/tasks/main.yml index 52c8975..f1f2119 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -28,7 +28,7 @@ - import_tasks: db_setup.yml when: - - "inventory_hostname == ((groups['blazar_all'] | intersect(ansible_play_hosts)) | list)[0]" + - _blazar_is_first_play_host vars: _oslodb_setup_host: "{{ blazar_db_setup_host }}" _oslodb_ansible_python_interpreter: "{{ blazar_db_setup_python_interpreter }}" @@ -45,7 +45,7 @@ - import_tasks: mq_setup.yml when: - - "inventory_hostname == ((groups['blazar_all'] | intersect(ansible_play_hosts)) | list)[0]" + - _blazar_is_first_play_host vars: _oslomsg_rpc_setup_host: "{{ blazar_oslomsg_rpc_setup_host }}" _oslomsg_rpc_userid: "{{ blazar_oslomsg_rpc_userid }}" @@ -88,7 +88,7 @@ - import_tasks: blazar_db_setup.yml when: - - "inventory_hostname == ((groups['blazar_all'] | intersect(ansible_play_hosts)) | list)[0]" + - _blazar_is_first_play_host tags: - blazar-config @@ -137,6 +137,6 @@ type: "{{ blazar_service_type }}" description: "{{ blazar_service_description }}" when: - - "inventory_hostname == ((groups['blazar_all'] | intersect(ansible_play_hosts)) | list)[0]" + - _blazar_is_first_play_host tags: - blazar-config diff --git a/vars/main.yml b/vars/main.yml index 6f324b7..738db91 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. +_blazar_is_first_play_host: "{{ (blazar_services['blazar-api']['group'] in group_names and inventory_hostname == ((groups[blazar_services['blazar-api']['group']] | intersect(ansible_play_hosts)) | list)[0]) | 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.