From 972a0aad6b5fb013cc27d8949a3bcb0fddadd613 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Wed, 8 Mar 2023 00:00:34 +0100 Subject: [PATCH] mgr: use state: 'auto' in ceph_mgr_module call so we can get rid of the complexity in the playbook Signed-off-by: Guillaume Abrioux --- library/ceph_mgr_module.py | 6 +++-- roles/ceph-mgr/tasks/mgr_modules.yml | 33 ++-------------------------- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/library/ceph_mgr_module.py b/library/ceph_mgr_module.py index c896c9faa..638e7811d 100644 --- a/library/ceph_mgr_module.py +++ b/library/ceph_mgr_module.py @@ -18,10 +18,12 @@ __metaclass__ = type from ansible.module_utils.basic import AnsibleModule try: from ansible.module_utils.ca_common import exit_module, \ + pre_generate_cmd, \ generate_cmd, \ is_containerized except ImportError: from module_utils.ca_common import exit_module, \ + pre_generate_cmd, \ generate_cmd, \ is_containerized import datetime @@ -114,8 +116,8 @@ def get_mgr_initial_modules(module, run_dir = get_run_dir(module, cluster, container_image) # /var/run/ceph/ceph-mon.mon0.asok socket_path = f"{run_dir}/{cluster}-mon.{node_name}.asok" - cmd = ['ceph', '--admin-daemon', socket_path, 'config', 'get', 'mgr_initial_modules', '--format', 'json'] - + cmd = pre_generate_cmd('ceph', container_image) + cmd.extend(['--admin-daemon', socket_path, 'config', 'get', 'mgr_initial_modules', '--format', 'json']) rc, out, err = module.run_command(cmd) if not rc and out: out = json.loads(out) diff --git a/roles/ceph-mgr/tasks/mgr_modules.yml b/roles/ceph-mgr/tasks/mgr_modules.yml index 0f1c54283..7a7c7fdc8 100644 --- a/roles/ceph-mgr/tasks/mgr_modules.yml +++ b/roles/ceph-mgr/tasks/mgr_modules.yml @@ -11,41 +11,12 @@ - (mgr_dump.stdout | from_json).available | bool when: not ansible_check_mode -- name: get enabled modules from ceph-mgr - command: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} --format json mgr module ls" - check_mode: no - changed_when: false - register: _ceph_mgr_modules - delegate_to: "{{ groups[mon_group_name][0] }}" - -- name: set _ceph_mgr_modules fact (convert _ceph_mgr_modules.stdout to a dict) - set_fact: - _ceph_mgr_modules: "{{ _ceph_mgr_modules.get('stdout', '{}') | from_json }}" - -- name: set _disabled_ceph_mgr_modules fact - set_fact: - _disabled_ceph_mgr_modules: "{% if _ceph_mgr_modules.disabled_modules | length == 0 %}[]{% elif _ceph_mgr_modules.disabled_modules[0] | type_debug != 'dict' %}{{ _ceph_mgr_modules['disabled_modules'] }}{% else %}{{ _ceph_mgr_modules['disabled_modules'] | map(attribute='name') | list }}{% endif %}" - -- name: disable ceph mgr enabled modules - ceph_mgr_module: - name: "{{ item }}" - cluster: "{{ cluster }}" - state: disable - environment: - CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}" - CEPH_CONTAINER_BINARY: "{{ container_binary }}" - with_items: "{{ _ceph_mgr_modules.get('enabled_modules', []) }}" - delegate_to: "{{ groups[mon_group_name][0] }}" - when: item not in ceph_mgr_modules - - name: add modules to ceph-mgr ceph_mgr_module: - name: "{{ item }}" + name: "{{ ceph_mgr_modules }}" cluster: "{{ cluster }}" - state: enable + state: auto environment: CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}" CEPH_CONTAINER_BINARY: "{{ container_binary }}" - with_items: "{{ ceph_mgr_modules }}" delegate_to: "{{ groups[mon_group_name][0] }}" - when: (item in _disabled_ceph_mgr_modules or _disabled_ceph_mgr_modules == [])