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: Ib50c2628d93fa3f5a707fa346c0270ec568f3306
This commit is contained in:
Dmitriy Rabotyagov 2020-09-11 14:27:25 +03:00 committed by Dmitriy Rabotyagov (noonedeadpunk)
parent 00d3bee584
commit a5e2a7e27b
2 changed files with 6 additions and 4 deletions

View File

@ -43,7 +43,7 @@
- import_tasks: db_setup.yml
when:
- inventory_hostname == groups['barbican_all'][0]
- _barbican_is_first_play_host
vars:
_oslodb_setup_host: "{{ barbican_db_setup_host }}"
_oslodb_databases:
@ -57,7 +57,7 @@
- import_tasks: mq_setup.yml
when:
- inventory_hostname == groups['barbican_all'][0]
- _barbican_is_first_play_host
vars:
_oslomsg_rpc_setup_host: "{{ barbican_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ barbican_oslomsg_rpc_userid }}"
@ -106,7 +106,7 @@
- import_tasks: barbican_db_sync.yml
when:
- inventory_hostname == groups['barbican_all'][0]
- _barbican_is_first_play_host
tags:
- barbican-config
@ -143,7 +143,7 @@
type: "{{ barbican_service_type }}"
description: "{{ barbican_service_description }}"
when:
- inventory_hostname == groups['barbican_all'][0]
- _barbican_is_first_play_host
tags:
- barbican-config

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
_barbican_is_first_play_host: "{{ (barbican_services['barbican-api']['group'] in group_names and inventory_hostname == (groups[barbican_services['barbican-api']['group']] | intersect(ansible_play_hosts)) | first) | 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.