From 2377702b335d9b4dc7324f05d6158e20d5f2190b Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Sun, 13 May 2018 18:53:01 +0100 Subject: [PATCH] Simplify fact setting The conditionals are currently difficult to follow. This simplifies them by splitting the fact setting up and doing a fact refresh after the first one is set. Change-Id: I3f74d06ba3b246674e3ea3eb6ee1e5ca6e86a79b --- tasks/glance_install.yml | 36 ++++++++++++++++----------------- tasks/glance_install_source.yml | 10 +++++++++ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/tasks/glance_install.yml b/tasks/glance_install.yml index da2235fe..23b96d3f 100644 --- a/tasks/glance_install.yml +++ b/tasks/glance_install.yml @@ -13,6 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +- name: Record the installation method + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: "glance" + option: "install_method" + value: "{{ glance_install_method }}" + +- name: Refresh local facts to ensure the glance section is present + setup: + filter: ansible_local + gather_subset: "!all" + - name: create the system group group: name: "{{ glance_system_group_name }}" @@ -90,7 +102,7 @@ update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" register: install_packages - until: install_packages|success + until: install_packages | success retries: 5 delay: 2 @@ -101,23 +113,11 @@ - name: Record the need for a service restart ini_file: dest: "/etc/ansible/facts.d/openstack_ansible.fact" - section: glance - option: "{{ item.name }}" - value: "{{ item.state }}" - with_items: - - name: "need_service_restart" - state: "True" - - name: "install_method" - state: "{{ glance_install_method }}" - when: (glance_install_method == 'source' and - ((glance_get_venv | changed) or - (glance_venv_dir | changed))) or - (install_packages | changed) or - (ansible_local is not defined) or - ('openstack_ansible' not in ansible_local) or - ('glance' not in ansible_local['openstack_ansible']) or - ('need_service_restart' not in ansible_local['openstack_ansible']['glance']) or - ('install_method' not in ansible_local['openstack_ansible']['glance']) + section: "glance" + option: "need_service_restart" + value: true + when: (install_packages | changed) or + ('need_service_restart' not in ansible_local['openstack_ansible']['glance']) - name: Run the systemd service role include_role: diff --git a/tasks/glance_install_source.yml b/tasks/glance_install_source.yml index 340d7813..28470520 100644 --- a/tasks/glance_install_source.yml +++ b/tasks/glance_install_source.yml @@ -120,6 +120,16 @@ tags: - skip_ansible_lint +- name: Record the need for a service restart + ini_file: + dest: "/etc/ansible/facts.d/openstack_ansible.fact" + section: "glance" + option: "need_service_restart" + value: true + when: (glance_get_venv | changed) or + (glance_venv_dir | changed) or + ('need_service_restart' not in ansible_local['openstack_ansible']['glance']) + - name: Record the venv tag deployed ini_file: dest: "/etc/ansible/facts.d/openstack_ansible.fact"