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 <gabrioux@ibm.com>
improve-ceph-mgr-module
Guillaume Abrioux 2023-03-08 00:00:34 +01:00
parent d8685aaef6
commit 972a0aad6b
2 changed files with 6 additions and 33 deletions

View File

@ -18,10 +18,12 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import exit_module, \ from ansible.module_utils.ca_common import exit_module, \
pre_generate_cmd, \
generate_cmd, \ generate_cmd, \
is_containerized is_containerized
except ImportError: except ImportError:
from module_utils.ca_common import exit_module, \ from module_utils.ca_common import exit_module, \
pre_generate_cmd, \
generate_cmd, \ generate_cmd, \
is_containerized is_containerized
import datetime import datetime
@ -114,8 +116,8 @@ def get_mgr_initial_modules(module,
run_dir = get_run_dir(module, cluster, container_image) run_dir = get_run_dir(module, cluster, container_image)
# /var/run/ceph/ceph-mon.mon0.asok # /var/run/ceph/ceph-mon.mon0.asok
socket_path = f"{run_dir}/{cluster}-mon.{node_name}.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) rc, out, err = module.run_command(cmd)
if not rc and out: if not rc and out:
out = json.loads(out) out = json.loads(out)

View File

@ -11,41 +11,12 @@
- (mgr_dump.stdout | from_json).available | bool - (mgr_dump.stdout | from_json).available | bool
when: not ansible_check_mode 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 - name: add modules to ceph-mgr
ceph_mgr_module: ceph_mgr_module:
name: "{{ item }}" name: "{{ ceph_mgr_modules }}"
cluster: "{{ cluster }}" cluster: "{{ cluster }}"
state: enable state: auto
environment: environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}" CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}" CEPH_CONTAINER_BINARY: "{{ container_binary }}"
with_items: "{{ ceph_mgr_modules }}"
delegate_to: "{{ groups[mon_group_name][0] }}" delegate_to: "{{ groups[mon_group_name][0] }}"
when: (item in _disabled_ceph_mgr_modules or _disabled_ceph_mgr_modules == [])