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: Ida1d88be3ae8f52b6c467563a9b99a7f7d44c4c0
This commit is contained in:
Dmitriy Rabotyagov
2020-09-11 15:49:52 +03:00
committed by Dmitriy Rabotyagov (noonedeadpunk)
parent ab5de45fa7
commit 1c2f04b028
3 changed files with 8 additions and 10 deletions

View File

@@ -108,7 +108,7 @@
dest: "{{ item.tmp_f }}"
flat: yes
changed_when: false
run_once: true
when: _glance_is_first_play_host
with_items: "{{ glance_core_files }}"
- name: Copy common config
@@ -130,7 +130,7 @@
state: absent
changed_when: false
delegate_to: localhost
run_once: true
when: _glance_is_first_play_host
with_items: "{{ glance_core_files }}"
# NOTE(cloudnull): This will ensure strong permissions on all rootwrap files.

View File

@@ -42,8 +42,7 @@
- import_tasks: db_setup.yml
when:
- "glance_services['glance-api']['group'] in group_names"
- "inventory_hostname == ((groups[glance_services['glance-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
- "_glance_is_first_play_host"
vars:
_oslodb_setup_host: "{{ glance_db_setup_host }}"
_oslodb_ansible_python_interpreter: "{{ glance_db_setup_python_interpreter }}"
@@ -60,8 +59,7 @@
- import_tasks: mq_setup.yml
when:
- "glance_services['glance-api']['group'] in group_names"
- "inventory_hostname == ((groups[glance_services['glance-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
- "_glance_is_first_play_host"
vars:
_oslomsg_rpc_setup_host: "{{ glance_oslomsg_rpc_setup_host }}"
_oslomsg_rpc_userid: "{{ glance_oslomsg_rpc_userid }}"
@@ -87,8 +85,7 @@
- import_tasks: glance_db_sync.yml
when:
- "glance_services['glance-api']['group'] in group_names"
- "inventory_hostname == ((groups[glance_services['glance-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
- "_glance_is_first_play_host"
tags:
- glance-config
@@ -119,8 +116,7 @@
url: "{{ glance_service_adminurl }}"
service: "{{ glance_service_name }}"
when:
- "glance_services['glance-api']['group'] in group_names"
- "inventory_hostname == ((groups[glance_services['glance-api']['group']]| intersect(ansible_play_hosts)) | list)[0]"
- "_glance_is_first_play_host"
tags:
- glance-config

View File

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