]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
ceph_key: fetch key when needed
authorGuillaume Abrioux <gabrioux@redhat.com>
Fri, 3 Apr 2020 16:23:00 +0000 (18:23 +0200)
committerDimitri Savineau <savineau.dimitri@gmail.com>
Fri, 3 Apr 2020 18:57:01 +0000 (14:57 -0400)
Fetch the key when it is present in the cluster but not on the node.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit ccfa249919b338197daec353cb5d4e535b3fb734)

library/ceph_key.py

index f309ca02a15bf2f3525a815f01bce442c5579a81..cd9e70c704524319b26c54e8a3d4e0da913f81f6 100644 (file)
@@ -582,8 +582,17 @@ def run_module():
                     caps = _info_key[0]['caps']
                 _caps = _info_key[0]['caps']
                 if secret == _secret and caps == _caps:
+                    if not os.path.isfile(file_path):
+                        rc, cmd, out, err = exec_commands(module, get_key(cluster, name, file_path, container_image))  # noqa E501
+                        result["rc"] = rc
+                        if rc != 0:
+                            result["stdout"] = "Couldn't fetch the key {0} at {1}.".format(name, file_path) # noqa E501
+                            module.exit_json(**result)
+                        result["stdout"] = "fetched the key {0} at {1}.".format(name, file_path) # noqa E501
+
                     result["stdout"] = "{0} already exists and doesn't need to be updated.".format(name) # noqa E501
                     result["rc"] = 0
+                    module.set_fs_attributes_if_different(file_args, False)
                     module.exit_json(**result)
         else:
             if os.path.isfile(file_path) and not secret or not caps:
@@ -607,17 +616,6 @@ def run_module():
                 result["stderr"] = err
                 module.exit_json(**result)
             changed = True
-        # fetch the key on the system
-        if key_exist != 1 and not import_key:
-            rc, cmd, out, err = exec_commands(module, get_key(cluster, name, file_path, container_image))  # noqa E501
-            result["rc"] = rc
-            if rc != 0:
-                result["stdout"] = "Couldn't fetch the key {0} at {1}.".format( # noqa E501
-                    name, file_path)
-                module.exit_json(**result)
-
-            result["stdout"] = "fetched the key {0} at {1}.".format(  # noqa E501
-                name, file_path)
 
         module.set_fs_attributes_if_different(file_args, False)