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: Iea777412d3bf7dc76b8073c51b4cdcb029573f66
This commit is contained in:
Dmitriy Rabotyagov 2020-09-11 16:21:26 +03:00 committed by Dmitriy Rabotyagov (noonedeadpunk)
parent 736334abd2
commit b11f705ea3
3 changed files with 7 additions and 7 deletions

View File

@ -49,9 +49,9 @@
dest: "{{ item.tmp_f }}"
flat: yes
changed_when: false
run_once: true
when:
- item.condition | bool
- _heat_is_first_play_host
with_items: "{{ heat_core_files }}"
- name: Copy common config

View File

@ -49,8 +49,7 @@
- import_tasks: db_setup.yml
when:
- "heat_services['heat-api']['group'] in group_names"
- "inventory_hostname == ((groups[heat_services['heat-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
- "_heat_is_first_play_host"
vars:
_oslodb_setup_host: "{{ heat_db_setup_host }}"
_oslodb_ansible_python_interpreter: "{{ heat_db_setup_python_interpreter }}"
@ -67,8 +66,7 @@
- import_tasks: mq_setup.yml
when:
- "heat_services['heat-api']['group'] in group_names"
- "inventory_hostname == ((groups[heat_services['heat-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
- "_heat_is_first_play_host"
vars:
_oslomsg_rpc_setup_host: "{{ heat_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ heat_oslomsg_rpc_userid }}"
@ -116,7 +114,7 @@
- import_tasks: heat_db_sync.yml
when:
- "inventory_hostname == ansible_play_hosts[0]"
- "_heat_is_first_play_host"
tags:
- heat-config
@ -132,7 +130,7 @@
- import_tasks: heat_service_setup.yml
when:
- "inventory_hostname == ansible_play_hosts[0]"
- "_heat_is_first_play_host"
tags:
- heat-config

View File

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