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.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/756310
Change-Id: I41d331fdb5ee95e0c9b9edbb3c7ee19ccd40d98c
This commit is contained in:
Dmitriy Rabotyagov 2020-11-30 14:17:32 +02:00
parent 41249b6bad
commit a202a34981
2 changed files with 5 additions and 3 deletions

View File

@ -28,7 +28,7 @@
- always
- import_tasks: db_setup.yml
when: inventory_hostname == groups['adjutant_all'][0]
when: _adjutant_is_first_play_host
vars:
_oslodb_setup_host: "{{ adjutant_galera_setup_host }}"
_oslodb_ansible_python_interpreter: "{{ adjutant_galera_setup_python_interpreter }}"
@ -70,7 +70,7 @@
- adjutant-config
- import_tasks: adjutant_db_sync.yml
when: inventory_hostname == groups['adjutant_all'][0]
when: _adjutant_is_first_play_host
tags:
- adjutant-config
@ -102,7 +102,7 @@
- interface: "admin"
url: "{{ adjutant_service_adminurl }}"
service: "{{ adjutant_service_name }}"
when: inventory_hostname == groups['adjutant_all'][0]
when: _adjutant_is_first_play_host
tags:
- adjutant-config

View File

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