From 17170992c33ed584793b9f70d7f0ab1443e96d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Fri, 14 Aug 2015 20:46:59 +0000 Subject: [PATCH] Ensure Python 2.4 compatibility and Linux-restricted support - Make build_entry compatible with Python 2.4 - Re-add missing warning/comment that was forgotten while refactoring - Replace `all()` with a good ol' for-loop Python 2.4 compatibility - Make a condition check more explicit (when `state` is `query`) - Make sure this module can only be run with on a Linux distribution - Add a note about Linux-only support in the documentation - Set the version in which recursive support was added, 2.0 --- lib/ansible/modules/files/acl.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/files/acl.py b/lib/ansible/modules/files/acl.py index 808e854ad84..133bb379329 100644 --- a/lib/ansible/modules/files/acl.py +++ b/lib/ansible/modules/files/acl.py @@ -21,6 +21,8 @@ version_added: "1.4" short_description: Sets and retrieves file ACL information. description: - Sets and retrieves file ACL information. +notes: + - As of Ansible 2.0, this module only supports Linux distributions. options: name: required: true @@ -80,7 +82,7 @@ options: - DEPRECATED. The acl to set or remove. This must always be quoted in the form of '::'. The qualifier may be empty for some types, but the type and perms are always requried. '-' can be used as placeholder when you do not care about permissions. This is now superseded by entity, type and permissions fields. recursive: - version_added: "@@@" + version_added: "2.0" required: false default: no choices: [ 'yes', 'no' ] @@ -150,7 +152,10 @@ def split_entry(entry): def build_entry(etype, entity, permissions=None): '''Builds and returns an entry string. Does not include the permissions bit if they are not provided.''' - return etype + ':' + entity + (':' + permissions if permissions else '') + if permissions: + return etype + ':' + entity + ':' + permissions + else: + return etype + ':' + entity def build_command(module, mode, path, follow, default, recursive, entry=''): @@ -163,6 +168,7 @@ def build_command(module, mode, path, follow, default, recursive, entry=''): cmd.append('-x "%s"' % entry) else: # mode == 'get' cmd = [module.get_bin_path('getfacl', True)] + # prevents absolute path warnings and removes headers cmd.append('--omit-header') cmd.append('--absolute-names') @@ -187,7 +193,11 @@ def acl_changed(module, cmd): cmd = cmd[:] # lists are mutables so cmd would be overriden without this cmd.insert(1, '--test') lines = run_acl(module, cmd) - return not all(line.endswith('*,*') for line in lines) + + for line in lines: + if not line.endswith('*,*'): + return False + return True def run_acl(module, cmd, check_rc=True): @@ -206,6 +216,9 @@ def run_acl(module, cmd, check_rc=True): def main(): + if get_platform().lower() != 'linux': + module.fail_json(msg="The acl module is only available for Linux distributions.") + module = AnsibleModule( argument_spec=dict( name=dict(required=True, aliases=['path'], type='str'), @@ -295,7 +308,7 @@ def main(): run_acl(module, command, False) msg = "%s is absent" % entry - else: + elif state == 'query': msg = "current acl" acl = run_acl(