Only try to stop services that exist

Test for the presence of services before trying to stop them.
Avoids a delay during initial deploy.

Change-Id: Id3ccba83a402074af77b62f67754a834d6f765b7
(cherry picked from commit 966b08123c)
This commit is contained in:
Jonathan Rosser 2018-03-08 21:14:19 +00:00 committed by Jesse Pretorius (odyssey4me)
parent 56e5de6458
commit 705f58fb0b
1 changed files with 11 additions and 9 deletions

View File

@ -44,25 +44,27 @@
- keystone-config
# When keystone is initially built, the service does not yet exist on the
# host this task is executed on. We therefore use failed_when for the task
# to catch a failure that's outside the norm.
- name: Ensure keystone service is stopped
# host this task is executed on. Detect the presence of the services.
- name: Test if keystone service exists
service:
name: "{{ item }}"
check_mode: yes
register: keystone_service_exists
with_items: "{{ keystone_wsgi_program_names }}"
- name: Ensure keystone service is stopped
service:
name: "{{ item.name }}"
state: stopped
register: _stop
until: _stop | success
retries: 5
delay: 2
with_items: "{{ keystone_wsgi_program_names }}"
with_items: "{{ keystone_service_exists.results }}"
when:
- "(ansible_local['openstack_ansible']['keystone']['need_db_expand'] | bool) or
(ansible_local['openstack_ansible']['keystone']['need_db_migrate'] | bool)"
failed_when:
- "_stop.msg is defined"
- "'no service or tool' not in _stop.msg"
- "'systemd could not find' not in _stop.msg"
- "'Could not find the requested service' not in _stop.msg"
- "(item.status['LoadState'] == 'loaded' | bool)"
notify:
- Manage LB
- Restart uWSGI