]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
ceph_orch_apply: fix idempotency
authorTeoman ONAY <tonay@ibm.com>
Tue, 28 May 2024 12:06:03 +0000 (14:06 +0200)
committerTeoman ONAY <tonay@redhat.com>
Wed, 29 May 2024 21:25:38 +0000 (23:25 +0200)
As is idempotency does not work as the ceph orch
output does contain more attributes than the expected
spec.

Signed-off-by: Teoman ONAY <tonay@ibm.com>
(cherry picked from commit 5a44fbeaa69273260f42257524df2e211b65c3ce)

library/ceph_orch_apply.py

index b163bbd09b03f029c0920a492cabf07610cc546a..0c876b24b2a697f219f86fef4d84357c10253d49 100644 (file)
@@ -103,6 +103,21 @@ def apply_spec(module: "AnsibleModule",
     return rc, cmd, out, err
 
 
+def change_required(current: Dict, expected: Dict) -> bool:
+    """ checks if the current config differs from what is expected """
+    if not current:
+        return True
+
+    for key, value in expected.items():
+        if key in current:
+            if current[key] != value:
+                return True
+            continue
+        else:
+            return True
+    return False
+
+
 def run_module() -> None:
 
     module_args = dict(
@@ -137,7 +152,7 @@ def run_module() -> None:
     expected = parse_spec(module.params.get('spec'))
     current_spec = retrieve_current_spec(module, expected)
 
-    if not current_spec or current_spec != expected:
+    if change_required(current_spec, expected):
         rc, cmd, out, err = apply_spec(module, spec)
         changed = True
     else: