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: Ia57c07c583be6e3fb9582b1d4a2da0deb4854154
This commit is contained in:
Dmitriy Rabotyagov 2020-09-11 11:35:44 +03:00 committed by Dmitriy Rabotyagov (noonedeadpunk)
parent 175e82adb6
commit 9d6c68acdd
2 changed files with 6 additions and 4 deletions

View File

@ -49,7 +49,7 @@
- import_tasks: db_setup.yml
when:
- inventory_hostname == groups['aodh_all'][0]
- _aodh_is_first_play_host
vars:
_oslodb_setup_host: "{{ aodh_db_setup_host }}"
_oslodb_databases:
@ -63,7 +63,7 @@
- import_tasks: mq_setup.yml
when:
- inventory_hostname == groups['aodh_all'][0]
- _aodh_is_first_play_host
vars:
_oslomsg_rpc_setup_host: "{{ aodh_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ aodh_oslomsg_rpc_userid }}"
@ -111,7 +111,7 @@
- import_tasks: aodh_db_sync.yml
when:
- inventory_hostname == groups['aodh_all'][0]
- _aodh_is_first_play_host
tags:
- aodh-config
@ -152,6 +152,6 @@
type: "{{ aodh_service_type }}"
description: "{{ aodh_service_description }}"
when:
- inventory_hostname == groups['aodh_all'][0]
- _aodh_is_first_play_host
tags:
- aodh-config

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
_aodh_is_first_play_host: "{{ (aodh_services['aodh-api']['group'] in group_names and inventory_hostname == (groups[aodh_services['aodh-api']['group']] | intersect(ansible_play_hosts)) | first) | bool }}"
filtered_aodh_services: |-
{% set services = [] %}
{% for key, value in aodh_services.items() %}