From 602f89baa63f362512ed1c2ce3628b414a41eded Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Thu, 11 Jul 2019 09:16:51 +0100 Subject: [PATCH] Fix glance with file backend Since https://review.opendev.org/647699/, we lost the logic to only deploy glance-api on a single host when using the file backend. This code was always a bit custom, and would be better supported by using the 'host_in_groups' pattern we have in a few other places where a single group name does not describe the placement of containers for a service. Change-Id: I21ce4a3b0beee0009ac69fecd0ce24efebaf158d Closes-Bug: #1836151 --- ansible/roles/glance/defaults/main.yml | 1 + ansible/roles/glance/tasks/ceph.yml | 12 +++++++++--- ansible/roles/glance/tasks/config.yml | 16 ++++++++-------- ansible/roles/glance/tasks/external_ceph.yml | 8 ++++++-- ansible/roles/glance/tasks/precheck.yml | 3 ++- ansible/roles/glance/tasks/pull.yml | 2 +- ansible/roles/glance/tasks/stop_service.yml | 3 +++ 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/ansible/roles/glance/defaults/main.yml b/ansible/roles/glance/defaults/main.yml index fc551a1ad6..ead1a8fe77 100644 --- a/ansible/roles/glance/defaults/main.yml +++ b/ansible/roles/glance/defaults/main.yml @@ -5,6 +5,7 @@ glance_services: glance-api: container_name: glance_api group: glance-api + host_in_groups: "{{ inventory_hostname in glance_api_hosts }}" enabled: true image: "{{ glance_api_image_full }}" environment: "{{ container_proxy }}" diff --git a/ansible/roles/glance/tasks/ceph.yml b/ansible/roles/glance/tasks/ceph.yml index 8acec68ea1..bc29bf2fb1 100644 --- a/ansible/roles/glance/tasks/ceph.yml +++ b/ansible/roles/glance/tasks/ceph.yml @@ -8,7 +8,9 @@ dest: "{{ node_config_directory }}/glance-api/ceph.conf" mode: "0660" become: true - when: inventory_hostname in groups['glance-api'] + when: + - glance_services['glance-api'].host_in_groups | bool + - glance_services['glance-api'].enabled | bool notify: - Restart glance-api container @@ -38,7 +40,9 @@ dest: "{{ node_config_directory }}/glance-api/ceph.client.glance.keyring" mode: "0600" become: true - when: inventory_hostname in groups['glance-api'] + when: + - glance_services['glance-api'].host_in_groups | bool + - glance_services['glance-api'].enabled | bool notify: - Restart glance-api container @@ -49,6 +53,8 @@ recurse: yes owner: "{{ config_owner_user }}" group: "{{ config_owner_group }}" - when: inventory_hostname in groups['glance-api'] + when: + - glance_services[item].host_in_groups | bool + - glance_services[item].enabled | bool with_items: - "glance-api" diff --git a/ansible/roles/glance/tasks/config.yml b/ansible/roles/glance/tasks/config.yml index dd34fbadca..5416ce6584 100644 --- a/ansible/roles/glance/tasks/config.yml +++ b/ansible/roles/glance/tasks/config.yml @@ -8,7 +8,7 @@ mode: "0770" become: true when: - - inventory_hostname in groups[item.value.group] + - item.value.host_in_groups | bool - item.value.enabled | bool with_dict: "{{ glance_services }}" @@ -19,7 +19,7 @@ - include_tasks: external_ceph.yml when: - - enable_ceph | bool == False + - not enable_ceph | bool - glance_backend_ceph | bool - name: Check if policies shall be overwritten @@ -47,7 +47,7 @@ become: true when: - item.value.enabled | bool - - inventory_hostname in groups[item.value.group] + - item.value.host_in_groups | bool with_dict: "{{ glance_services }}" notify: - Restart {{ item.key }} container @@ -67,7 +67,7 @@ become: true when: - item.value.enabled | bool - - inventory_hostname in groups[item.value.group] + - item.value.host_in_groups | bool with_dict: "{{ glance_services }}" notify: - Restart {{ item.key }} container @@ -86,7 +86,7 @@ become: true when: - glance_api.enabled | bool - - inventory_hostname in groups[glance_api.group] + - glance_api.host_in_groups | bool - enable_glance_image_cache | bool notify: - Restart glance-api container @@ -105,7 +105,7 @@ become: true when: - glance_api.enabled | bool - - inventory_hostname in groups[glance_api.group] + - glance_api.host_in_groups | bool - glance_backend_swift | bool notify: - Restart glance-api container @@ -118,7 +118,7 @@ become: true when: - glance_policy_file is defined - - inventory_hostname in groups[item.value.group] + - item.value.host_in_groups | bool - item.value.enabled | bool with_dict: "{{ glance_services }}" notify: @@ -136,7 +136,7 @@ dimensions: "{{ item.value.dimensions }}" when: - kolla_action != "config" - - inventory_hostname in groups[item.value.group] + - item.value.host_in_groups | bool - item.value.enabled | bool with_dict: "{{ glance_services }}" notify: diff --git a/ansible/roles/glance/tasks/external_ceph.yml b/ansible/roles/glance/tasks/external_ceph.yml index 33b20731b8..62c977bd49 100644 --- a/ansible/roles/glance/tasks/external_ceph.yml +++ b/ansible/roles/glance/tasks/external_ceph.yml @@ -5,7 +5,9 @@ dest: "{{ node_config_directory }}/glance-api/" mode: "0660" become: true - when: inventory_hostname in groups['glance-api'] + when: + - glance_services['glance-api'].host_in_groups | bool + - glance_services['glance-api'].enabled | bool with_fileglob: - "{{ node_custom_config }}/glance/ceph*" notify: @@ -18,6 +20,8 @@ owner: "{{ config_owner_user }}" group: "{{ config_owner_group }}" become: true - when: inventory_hostname in groups['glance-api'] + when: + - glance_services[item].host_in_groups | bool + - glance_services[item].enabled | bool with_items: - "glance-api" diff --git a/ansible/roles/glance/tasks/precheck.yml b/ansible/roles/glance/tasks/precheck.yml index 2be891740d..49337a4e77 100644 --- a/ansible/roles/glance/tasks/precheck.yml +++ b/ansible/roles/glance/tasks/precheck.yml @@ -13,5 +13,6 @@ timeout: 1 state: stopped when: - - inventory_hostname in groups[glance_services['glance-api']['group']] + - glance_services['glance-api'].host_in_groups | bool + - glance_services['glance-api'].enabled | bool - container_facts['glance_api'] is not defined diff --git a/ansible/roles/glance/tasks/pull.yml b/ansible/roles/glance/tasks/pull.yml index d12f8d304b..1de70396f6 100644 --- a/ansible/roles/glance/tasks/pull.yml +++ b/ansible/roles/glance/tasks/pull.yml @@ -6,6 +6,6 @@ common_options: "{{ docker_common_options }}" image: "{{ item.value.image }}" when: - - inventory_hostname in groups[item.value.group] + - item.value.host_in_groups | bool - item.value.enabled | bool with_dict: "{{ glance_services }}" diff --git a/ansible/roles/glance/tasks/stop_service.yml b/ansible/roles/glance/tasks/stop_service.yml index fa4d019ca0..a98c460757 100644 --- a/ansible/roles/glance/tasks/stop_service.yml +++ b/ansible/roles/glance/tasks/stop_service.yml @@ -7,3 +7,6 @@ action: "stop_container" common_options: "{{ docker_common_options }}" name: "{{ glance_api.container_name }}" + when: + - glance_api.host_in_groups | bool + - glance_api.enabled | bool