From b1cf342b2719680df629d179de45d446de174cc2 Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Thu, 10 Aug 2017 15:42:36 +0100 Subject: [PATCH] Move to use filtered packages/services/clients Instead of passing a huge dict lets filter the services so that only the required packages are installed (in one command). Additionally, we can perform a similar filtering for the services and clients that are used as a part of the ceph_components var. Change-Id: I64cced1bf82c9d7b4368873eff524603b91162c8 --- handlers/main.yml | 7 ++----- tasks/ceph_auth.yml | 16 +++------------- tasks/ceph_install.yml | 7 +------ vars/main.yml | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 4dc76d6..7c69624 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -14,11 +14,8 @@ - name: Restart os services service: - name: "{{ item.1 }}" + name: "{{ item }}" state: restarted - with_subelements: - - "{{ ceph_components + ceph_extra_components }}" - - service - when: inventory_hostname in groups[item.0.component] + with_items: "{{ ceph_client_filtered_services }}" failed_when: false diff --git a/tasks/ceph_auth.yml b/tasks/ceph_auth.yml index f5cc488..9741fb8 100644 --- a/tasks/ceph_auth.yml +++ b/tasks/ceph_auth.yml @@ -20,17 +20,8 @@ # the first get makes sure the client exists, so the second only runs when it # exists, the trick is the different output of both, the second has the right # output to put in a keyring; ceph admin should have already created the user - shell: ceph auth get client.{{ item.1 }} >/dev/null && ceph auth get-or-create client.{{ item.1 }} - with_subelements: - - "{{ ceph_components + ceph_extra_components }}" - - client - when: - - inventory_hostname in groups[item.0.component] - - (item.0.component != 'cinder_backup' or - ((cinder_service_backup_program_enabled is defined and - cinder_service_backup_program_enabled | bool) and - (cinder_service_backup_driver is defined and - cinder_service_backup_driver == 'cinder.backup.drivers.ceph'))) + shell: ceph auth get client.{{ item }} >/dev/null && ceph auth get-or-create client.{{ item }} + with_items: "{{ ceph_client_filtered_clients }}" changed_when: false delegate_to: '{{ ceph_mon_host }}' register: ceph_client_keyrings @@ -59,7 +50,7 @@ # ceph get-or-create ... ... -o file? template: src: ceph.client.keyring.j2 - dest: /etc/ceph/ceph.client.{{ item.item.1 }}.keyring + dest: /etc/ceph/ceph.client.{{ item.item }}.keyring backup: true owner: root # TODO @@ -74,7 +65,6 @@ with_items: "{{ ceph_client_keyrings.results }}" when: - not item | skipped - - inventory_hostname in groups[item.item.0.component] notify: - Restart os services diff --git a/tasks/ceph_install.yml b/tasks/ceph_install.yml index 68c40cc..63f8487 100644 --- a/tasks/ceph_install.yml +++ b/tasks/ceph_install.yml @@ -15,7 +15,7 @@ - name: Install ceph packages package: - name: '{{ item.1 }}' + name: '{{ ceph_client_filtered_packages }}' state: "{{ ceph_client_package_state }}" update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" @@ -23,10 +23,5 @@ until: install_packages|success retries: 5 delay: 2 - with_subelements: - - "{{ ceph_components + ceph_extra_components }}" - - package - when: - - inventory_hostname in groups[item.0.component] notify: - Restart os services diff --git a/vars/main.yml b/vars/main.yml index 02ee160..002b55d 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -56,3 +56,42 @@ ceph_extra_components: [] # client: # - '{{ gnocchi_ceph_client }}' # service: '{{ ceph_gnocchi_service_names }}' + +ceph_client_filtered_packages: |- + {% set packages = [] %} + {% for comp in (ceph_components + ceph_extra_components) %} + {% if comp.component in group_names %} + {% for pkg_name in comp.package %} + {% if pkg_name not in packages %} + {% set _ = packages.apend(pkg_name) %} + {% endif %} + {% endfor %} + {% endif %} + {% endfor %} + {{ packages }} + +ceph_client_filtered_services: |- + {% set services = [] %} + {% for comp in (ceph_components + ceph_extra_components) %} + {% if comp.component in group_names %} + {% set _ = services.append(comp.service) %} + {% endif %} + {% endfor %} + {{ service }} + +ceph_client_filtered_clients: |- + {% set clients = [] %} + {% for comp in (ceph_components + ceph_extra_components) %} + {% if comp.component in group_names %} + {% if ((comp.component != 'cinder_backup') or + ((cinder_service_backup_program_enabled is defined and + cinder_service_backup_program_enabled | bool) and + (cinder_service_backup_driver is defined and + cinder_service_backup_driver == 'cinder.backup.drivers.ceph'))) %} + {% for client in comp.client %} + {% _ = clients.append(client) + {% endfor %} + {% endif %} + {% endif %} + {% endfor %} + {{ clients }}