From 6e0e17a7e35182cc7d286df14e53ada4c5e8a515 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 1 Dec 2021 06:58:39 +0100 Subject: [PATCH] xattr - invoke run_command passing list (#3806) (#3820) * xattr - invoke run_command passing list * added changelog fragment * Update plugins/modules/files/xattr.py Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit 2edbabd30f27d261173ec166b2d4fc01550fc22f) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- .../3806-xattr-run_command-list.yaml | 2 ++ plugins/modules/files/xattr.py | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 changelogs/fragments/3806-xattr-run_command-list.yaml diff --git a/changelogs/fragments/3806-xattr-run_command-list.yaml b/changelogs/fragments/3806-xattr-run_command-list.yaml new file mode 100644 index 0000000000..ca90f6209d --- /dev/null +++ b/changelogs/fragments/3806-xattr-run_command-list.yaml @@ -0,0 +1,2 @@ +minor_changes: + - xattr - calling ``run_command`` with arguments as ``list`` instead of ``str`` (https://github.com/ansible-collections/community.general/pull/3806). diff --git a/plugins/modules/files/xattr.py b/plugins/modules/files/xattr.py index 21d71170d1..c0867892d3 100644 --- a/plugins/modules/files/xattr.py +++ b/plugins/modules/files/xattr.py @@ -12,9 +12,9 @@ DOCUMENTATION = ''' module: xattr short_description: Manage user defined extended attributes description: - - Manages filesystem user defined extended attributes. - - Requires that extended attributes are enabled on the target filesystem - and that the setfattr/getfattr utilities are present. + - Manages filesystem user defined extended attributes. + - Requires that extended attributes are enabled on the target filesystem + and that the setfattr/getfattr utilities are present. options: path: description: @@ -34,13 +34,13 @@ options: type: str value: description: - - The value to set the named name/key to, it automatically sets the C(state) to 'set'. + - The value to set the named name/key to, it automatically sets the I(state) to C(present). type: str state: description: - defines which state you want to do. - C(read) retrieves the current value for a C(key) (default) - C(present) sets C(name) to C(value), default if value is set + C(read) retrieves the current value for a I(key) (default) + C(present) sets I(path) to C(value), default if value is set C(all) dumps all data C(keys) retrieves all keys C(absent) deletes the key @@ -49,14 +49,14 @@ options: default: read follow: description: - - If C(yes), dereferences symlinks and sets/gets attributes on symlink target, + - If C(true), dereferences symlinks and sets/gets attributes on symlink target, otherwise acts on symlink itself. type: bool - default: yes + default: true notes: - As of Ansible 2.3, the I(name) option has been changed to I(path) as default, but I(name) still works as well. author: -- Brian Coca (@bcoca) + - Brian Coca (@bcoca) ''' EXAMPLES = ''' @@ -116,7 +116,8 @@ def get_xattr(module, path, key, follow): if key is None: cmd.append('-d') else: - cmd.append('-n %s' % key) + cmd.append('-n') + cmd.append(key) cmd.append(path) return _run_xattr(module, cmd, False) @@ -127,8 +128,10 @@ def set_xattr(module, path, key, value, follow): cmd = [module.get_bin_path('setfattr', True)] if not follow: cmd.append('-h') - cmd.append('-n %s' % key) - cmd.append('-v %s' % value) + cmd.append('-n') + cmd.append(key) + cmd.append('-v') + cmd.append(value) cmd.append(path) return _run_xattr(module, cmd) @@ -139,7 +142,8 @@ def rm_xattr(module, path, key, follow): cmd = [module.get_bin_path('setfattr', True)] if not follow: cmd.append('-h') - cmd.append('-x %s' % key) + cmd.append('-x') + cmd.append(key) cmd.append(path) return _run_xattr(module, cmd, False) @@ -148,7 +152,7 @@ def rm_xattr(module, path, key, follow): def _run_xattr(module, cmd, check_rc=True): try: - (rc, out, err) = module.run_command(' '.join(cmd), check_rc=check_rc) + (rc, out, err) = module.run_command(cmd, check_rc=check_rc) except Exception as e: module.fail_json(msg="%s!" % to_native(e))