]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
ceph_key: apply permissions using ansible code module
authorSébastien Han <seb@redhat.com>
Fri, 16 Nov 2018 09:46:10 +0000 (10:46 +0100)
committerGuillaume Abrioux <gabrioux@redhat.com>
Mon, 3 Dec 2018 13:39:43 +0000 (14:39 +0100)
Instead of applying file permissions from our code, let's rely on the
ansible code 'file' module for this. This is now handled at the task
declaration level instead of inside the module.

Signed-off-by: Sébastien Han <seb@redhat.com>
library/ceph_key.py

index 9b42a06b73157fb884d4465ad2dae4171d29b512..710f339013e4a9eb618e2bd8c97989cefe75a385 100644 (file)
@@ -649,14 +649,6 @@ def run_module():
         if entities is None:
             fatal("Failed to find some of the initial entities", module)
 
-        # get ceph's group and user id
-        if container_image:
-            ceph_uid = os.getenv('CEPH_UID')
-            ceph_grp = os.getenv('CEPH_UID')
-        else:
-            ceph_uid = pwd.getpwnam('ceph').pw_uid
-            ceph_grp = grp.getgrnam('ceph').gr_gid
-
         output_format = "plain"
         for entity in entities:
             key_path = build_key_path(cluster, entity)
@@ -679,18 +671,9 @@ def run_module():
             rc, cmd, out, err = exec_commands(
                 module, info_cmd)  # noqa E501
 
-            # apply ceph:ceph ownership and mode 0400 on keys
-            # FIXME by using
-            # file_args = module.load_file_common_arguments(module.params)
-            # file_args['path'] = dest
-            # module.set_fs_attributes_if_different(file_args, False)
-            try:
-                os.chown(key_path, ceph_uid, ceph_grp)
-                os.chmod(key_path, stat.S_IRUSR)
-            except OSError as e:
-                fatal("Failed to set owner/group/permissions of %s: %s" % (
-                    key_path, str(e)), module)
-
+            file_args = module.load_file_common_arguments(module.params)
+            file_args['path'] = key_path
+            module.set_fs_attributes_if_different(file_args, False)
     else:
         module.fail_json(
             msg='State must either be "present" or "absent" or "update" or "list" or "info" or "fetch_initial_keys".', changed=False, rc=1)  # noqa E501