mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
xattr - invoke run_command passing list (#3806)
* 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>
This commit is contained in:
parent
2896131ca7
commit
2edbabd30f
2 changed files with 20 additions and 14 deletions
2
changelogs/fragments/3806-xattr-run_command-list.yaml
Normal file
2
changelogs/fragments/3806-xattr-run_command-list.yaml
Normal file
|
@ -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).
|
|
@ -12,9 +12,9 @@ DOCUMENTATION = '''
|
||||||
module: xattr
|
module: xattr
|
||||||
short_description: Manage user defined extended attributes
|
short_description: Manage user defined extended attributes
|
||||||
description:
|
description:
|
||||||
- Manages filesystem user defined extended attributes.
|
- Manages filesystem user defined extended attributes.
|
||||||
- Requires that extended attributes are enabled on the target filesystem
|
- Requires that extended attributes are enabled on the target filesystem
|
||||||
and that the setfattr/getfattr utilities are present.
|
and that the setfattr/getfattr utilities are present.
|
||||||
options:
|
options:
|
||||||
path:
|
path:
|
||||||
description:
|
description:
|
||||||
|
@ -34,13 +34,13 @@ options:
|
||||||
type: str
|
type: str
|
||||||
value:
|
value:
|
||||||
description:
|
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
|
type: str
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- defines which state you want to do.
|
- defines which state you want to do.
|
||||||
C(read) retrieves the current value for a C(key) (default)
|
C(read) retrieves the current value for a I(key) (default)
|
||||||
C(present) sets C(name) to C(value), default if value is set
|
C(present) sets I(path) to C(value), default if value is set
|
||||||
C(all) dumps all data
|
C(all) dumps all data
|
||||||
C(keys) retrieves all keys
|
C(keys) retrieves all keys
|
||||||
C(absent) deletes the key
|
C(absent) deletes the key
|
||||||
|
@ -49,14 +49,14 @@ options:
|
||||||
default: read
|
default: read
|
||||||
follow:
|
follow:
|
||||||
description:
|
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.
|
otherwise acts on symlink itself.
|
||||||
type: bool
|
type: bool
|
||||||
default: yes
|
default: true
|
||||||
notes:
|
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.
|
- 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:
|
author:
|
||||||
- Brian Coca (@bcoca)
|
- Brian Coca (@bcoca)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -116,7 +116,8 @@ def get_xattr(module, path, key, follow):
|
||||||
if key is None:
|
if key is None:
|
||||||
cmd.append('-d')
|
cmd.append('-d')
|
||||||
else:
|
else:
|
||||||
cmd.append('-n %s' % key)
|
cmd.append('-n')
|
||||||
|
cmd.append(key)
|
||||||
cmd.append(path)
|
cmd.append(path)
|
||||||
|
|
||||||
return _run_xattr(module, cmd, False)
|
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)]
|
cmd = [module.get_bin_path('setfattr', True)]
|
||||||
if not follow:
|
if not follow:
|
||||||
cmd.append('-h')
|
cmd.append('-h')
|
||||||
cmd.append('-n %s' % key)
|
cmd.append('-n')
|
||||||
cmd.append('-v %s' % value)
|
cmd.append(key)
|
||||||
|
cmd.append('-v')
|
||||||
|
cmd.append(value)
|
||||||
cmd.append(path)
|
cmd.append(path)
|
||||||
|
|
||||||
return _run_xattr(module, cmd)
|
return _run_xattr(module, cmd)
|
||||||
|
@ -139,7 +142,8 @@ def rm_xattr(module, path, key, follow):
|
||||||
cmd = [module.get_bin_path('setfattr', True)]
|
cmd = [module.get_bin_path('setfattr', True)]
|
||||||
if not follow:
|
if not follow:
|
||||||
cmd.append('-h')
|
cmd.append('-h')
|
||||||
cmd.append('-x %s' % key)
|
cmd.append('-x')
|
||||||
|
cmd.append(key)
|
||||||
cmd.append(path)
|
cmd.append(path)
|
||||||
|
|
||||||
return _run_xattr(module, cmd, False)
|
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):
|
def _run_xattr(module, cmd, check_rc=True):
|
||||||
|
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
module.fail_json(msg="%s!" % to_native(e))
|
module.fail_json(msg="%s!" % to_native(e))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue