From 0b87c99719671e1b74a43bc777844ffcf4769d25 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Tue, 25 Apr 2023 14:47:30 +0200 Subject: [PATCH 1/2] preflight: update required repos for epel 'powertools' is for el8 whereas we need 'crb' for el9 Signed-off-by: Guillaume Abrioux (cherry picked from commit b360872016a36c28e7df89ff07a4560ffb45e55a) --- cephadm-preflight.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cephadm-preflight.yml b/cephadm-preflight.yml index 72dde4c..f7cbd22 100644 --- a/cephadm-preflight.yml +++ b/cephadm-preflight.yml @@ -144,8 +144,8 @@ - name: install epel-release when: ansible_facts['distribution'] == 'CentOS' block: - - name: enable CentOS PowerTools repository for epel - command: dnf config-manager --set-enabled powertools + - name: enable required CentOS repository for epel + command: dnf config-manager --set-enabled "{{ 'powertools' if ansible_facts['distribution_major_version'] == '8' else 'crb' }}" changed_when: false - name: install package From 76ec3992758206c7a2ede1ae09220836a5c51716 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Tue, 25 Apr 2023 14:23:54 +0200 Subject: [PATCH 2/2] library: fix a bug in ceph_config module `ceph config get` doesn't allow getting value when entity is 'global' so it makes the module fail. Indeed, the module first tries to get the current value of the option for idempotency concern. The idea is to check in `ceph config dump` instead. Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2188319 Signed-off-by: Guillaume Abrioux (cherry picked from commit b28fe122a9757c274bb79381d095647a859b33cb) --- library/ceph_config.py | 48 ++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/library/ceph_config.py b/library/ceph_config.py index 8758be3..57df331 100644 --- a/library/ceph_config.py +++ b/library/ceph_config.py @@ -13,6 +13,7 @@ from module_utils.ceph_common import exit_module, build_base_cmd_shell, fatal # type: ignore import datetime +import json ANSIBLE_METADATA = { 'metadata_version': '1.1', @@ -84,22 +85,35 @@ RETURN = '''# ''' -def get_or_set_option(module: "AnsibleModule", - action: str, - who: str, - option: str, - value: str) -> Tuple[int, List[str], str, str]: +def set_option(module: "AnsibleModule", + who: str, + option: str, + value: str) -> Tuple[int, List[str], str, str]: cmd = build_base_cmd_shell(module) - cmd.extend(['ceph', 'config', action, who, option]) - - if action == 'set': - cmd.append(value) + cmd.extend(['ceph', 'config', 'set', who, option, value]) rc, out, err = module.run_command(cmd) return rc, cmd, out.strip(), err +def get_config_dump(module: "AnsibleModule"): + cmd = build_base_cmd_shell(module) + cmd.extend(['ceph', 'config', 'dump', '--format', 'json']) + rc, out, err = module.run_command(cmd) + if rc: + fatal(message=f"Can't get current configuration via `ceph config dump`.Error:\n{err}", module=module) + out = out.strip() + return rc, cmd, out, err + + +def get_current_value(who, option, config_dump): + for config in config_dump: + if config['section'] == who and config['name'] == option: + return config['value'] + return None + + def main() -> None: module = AnsibleModule( argument_spec=dict( @@ -135,16 +149,22 @@ def main() -> None: startd = datetime.datetime.now() changed = False - rc, cmd, out, err = get_or_set_option(module, 'get', who, option, value) - if rc: - fatal(message=f"Can't get current value. who={who} option={option}", module=module) + rc, cmd, out, err = get_config_dump(module) + config_dump = json.loads(out) + current_value = get_current_value(who, option, config_dump) if action == 'set': - if value.lower() == out: + if value.lower() == current_value: out = 'who={} option={} value={} already set. Skipping.'.format(who, option, value) else: - rc, cmd, out, err = get_or_set_option(module, action, who, option, value) + rc, cmd, out, err = set_option(module, who, option, value) changed = True + else: + if current_value is None: + out = '' + err = 'No value found for who={} option={}'.format(who, option) + else: + out = current_value exit_module(module=module, out=out, rc=rc, cmd=cmd, err=err, startd=startd,