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: I5c92722d5e7c49d0a01c7e9dbd0b254b5bea6dc4
This commit is contained in:
Dmitriy Rabotyagov 2020-09-25 18:29:03 +03:00
parent 2e04617116
commit 353dc3d050
2 changed files with 5 additions and 4 deletions

View File

@ -29,7 +29,7 @@
- import_tasks: db_setup.yml
when:
- inventory_hostname == groups['tacker_all'][0]
- _tacker_is_first_play_host
vars:
_oslodb_setup_host: "{{ tacker_db_setup_host }}"
_oslodb_ansible_python_interpreter: "{{ tacker_db_setup_python_interpreter }}"
@ -46,7 +46,7 @@
- import_tasks: mq_setup.yml
when:
- inventory_hostname == groups['tacker_all'][0]
- _tacker_is_first_play_host
vars:
_oslomsg_rpc_setup_host: "{{ tacker_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ tacker_oslomsg_rpc_userid }}"
@ -114,7 +114,7 @@
- import_tasks: tacker_db_sync.yml
when:
- inventory_hostname == groups['tacker_all'][0]
- _tacker_is_first_play_host
tags:
- tacker-install
@ -145,7 +145,7 @@
type: "{{ tacker_service_type }}"
description: "{{ tacker_service_description }}"
when:
- inventory_hostname == groups['tacker_all'][0]
- _tacker_is_first_play_host
tags:
- tacker-install

View File

@ -15,3 +15,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
_tacker_is_first_play_host: "{{ ('tacker_all' in group_names and inventory_hostname == (groups['tacker_all'] | intersect(ansible_play_hosts)) | first) | bool }}"