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: I33362163d54a1b54ba4a0cd13764f28fe6485040
This commit is contained in:
parent
0dcd1ba011
commit
602e895307
|
@ -25,8 +25,7 @@
|
|||
|
||||
- import_tasks: db_setup.yml
|
||||
when:
|
||||
- "sahara_services['sahara-api']['group'] in group_names"
|
||||
- "inventory_hostname == ((groups[sahara_services['sahara-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
|
||||
- _sahara_is_first_play_host
|
||||
vars:
|
||||
_oslodb_setup_host: "{{ sahara_db_setup_host }}"
|
||||
_oslodb_ansible_python_interpreter: "{{ sahara_db_setup_python_interpreter }}"
|
||||
|
@ -43,8 +42,7 @@
|
|||
|
||||
- import_tasks: mq_setup.yml
|
||||
when:
|
||||
- "sahara_services['sahara-api']['group'] in group_names"
|
||||
- "inventory_hostname == ((groups[sahara_services['sahara-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
|
||||
- _sahara_is_first_play_host
|
||||
vars:
|
||||
_oslomsg_rpc_setup_host: "{{ sahara_oslomsg_rpc_setup_host }}"
|
||||
_oslomsg_rpc_userid: "{{ sahara_oslomsg_rpc_userid }}"
|
||||
|
@ -118,7 +116,7 @@
|
|||
- systemd-service
|
||||
|
||||
- import_tasks: sahara_db_sync.yml
|
||||
when: inventory_hostname == groups['sahara_all'][0]
|
||||
when: _sahara_is_first_play_host
|
||||
tags:
|
||||
- sahara-config
|
||||
|
||||
|
@ -149,7 +147,7 @@
|
|||
- name: "{{ sahara_service_name }}"
|
||||
type: "{{ sahara_service_type }}"
|
||||
description: "{{ sahara_service_description }}"
|
||||
when: inventory_hostname == groups['sahara_all'][0]
|
||||
when: _sahara_is_first_play_host
|
||||
tags:
|
||||
- sahara-config
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
_sahara_is_first_play_host: "{{ (sahara_services['sahara-api']['group'] in group_names and inventory_hostname == (groups[sahara_services['sahara-api']['group']] | intersect(ansible_play_hosts)) | first) | bool }}"
|
||||
|
||||
filtered_sahara_services: |-
|
||||
{% set services = [] %}
|
||||
{% for key, value in sahara_services.items() %}
|
||||
|
|
Loading…
Reference in New Issue