From 4bc7bb2766005393f13e6fb262438d8cbb7d10ae Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Fri, 3 Apr 2020 18:23:00 +0200 Subject: [PATCH] ceph_key: fetch key when needed Fetch the key when it is present in the cluster but not on the node. Signed-off-by: Guillaume Abrioux (cherry picked from commit ccfa249919b338197daec353cb5d4e535b3fb734) --- library/ceph_key.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/library/ceph_key.py b/library/ceph_key.py index f309ca02a..cd9e70c70 100644 --- a/library/ceph_key.py +++ b/library/ceph_key.py @@ -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)