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: Iadca3596f21f83bdb090c8bf45b323bf04154e92
This commit is contained in:
Dmitriy Rabotyagov
2020-09-14 16:08:01 +03:00
committed by Dmitriy Rabotyagov (noonedeadpunk)
parent f6cd496e8e
commit 6c127934e9
2 changed files with 6 additions and 8 deletions

View File

@ -27,8 +27,7 @@
- import_tasks: db_setup.yml
when:
- "masakari_services['masakari-api']['group'] in group_names"
- "inventory_hostname == ((groups[masakari_services['masakari-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
- "_masakari_is_first_play_host"
vars:
_oslodb_setup_host: "{{ masakari_db_setup_host }}"
_oslodb_ansible_python_interpreter: "{{ masakari_db_setup_python_interpreter }}"
@ -45,8 +44,7 @@
- import_tasks: mq_setup.yml
when:
- "masakari_services['masakari-api']['group'] in group_names"
- "inventory_hostname == ((groups[masakari_services['masakari-api']['group']] | intersect(ansible_play_hosts)) | list)[0]"
- "_masakari_is_first_play_host"
vars:
_oslomsg_rpc_setup_host: "{{ masakari_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ masakari_oslomsg_rpc_userid }}"
@ -119,8 +117,7 @@
- import_tasks: masakari_db_sync.yml
when:
- "masakari_services['masakari-api']['group'] in group_names"
- "inventory_hostname == ((groups[masakari_services['masakari-api']['group']] | intersect(ansible_play_hosts)) | list)[0]"
- "_masakari_is_first_play_host"
- import_tasks: service_setup.yml
vars:
@ -149,8 +146,7 @@
type: "{{ masakari_service_type }}"
description: "{{ masakari_service_description }}"
when:
- "masakari_services['masakari-api']['group'] in group_names"
- "inventory_hostname == ((groups[masakari_services['masakari-api']['group']] | intersect(ansible_play_hosts)) | list)[0]"
- "_masakari_is_first_play_host"
tags:
- masakari-config

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
_masakari_is_first_play_host: "{{ (masakari_services['masakari-api']['group'] in group_names and inventory_hostname == (groups[masakari_services['masakari-api']['group']] | intersect(ansible_play_hosts)) | first) | bool }}"
masakari_pip_venv_packages: |-
{% set pip_packages = [] %}
{% if masakari_services['masakari-api']['group'] in group_names or masakari_services['masakari-engine']['group'] in group_names %}