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: If086478f8ea9a0ffb763fd05d6a110e1c12f32b3
This commit is contained in:
Dmitriy Rabotyagov 2020-09-25 17:54:07 +03:00
parent 3361c4663c
commit 2bcd1ac750
2 changed files with 4 additions and 4 deletions

View File

@ -42,8 +42,7 @@
- import_tasks: db_setup.yml
when:
- "placement_services['placement-api']['group'] in group_names"
- "inventory_hostname == ((groups[placement_services['placement-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
- _placement_is_first_play_host
vars:
_oslodb_setup_host: "{{ placement_db_setup_host }}"
_oslodb_ansible_python_interpreter: "{{ placement_db_setup_python_interpreter }}"
@ -71,7 +70,7 @@
- placement-config
- import_tasks: placement_db_sync.yml
run_once: true
when: _placement_is_first_play_host
tags:
- placement-config
@ -111,7 +110,7 @@
- name: "{{ placement_service_name }}"
type: "{{ placement_service_type }}"
description: "{{ placement_service_description }}"
run_once: true
when: _placement_is_first_play_host
tags:
- placement-config

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
_placement_is_first_play_host: "{{ (placement_services['placement-api']['group'] in group_names and inventory_hostname == (groups[placement_services['placement-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.