Skip to content

Commit

Permalink
xattr - invoke run_command passing list (#3806)
Browse files Browse the repository at this point in the history
* xattr - invoke run_command passing list

* added changelog fragment

* Update plugins/modules/files/xattr.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
  • Loading branch information
russoz and felixfontein authored Nov 30, 2021
1 parent 2896131 commit 2edbabd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/3806-xattr-run_command-list.yaml
Original file line number Diff line number Diff line change
@@ -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).
32 changes: 18 additions & 14 deletions plugins/modules/files/xattr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
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:
Expand All @@ -34,13 +34,13 @@
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
Expand All @@ -49,14 +49,14 @@
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 = '''
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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))

Expand Down

0 comments on commit 2edbabd

Please sign in to comment.