community.general.xattr_info module – Retrieve filesystem extended attributes

Note

This module is part of the community.general collection (version 14.0.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.xattr_info.

New in community.general 14.0.0

Synopsis

  • Retrieves filesystem extended attributes of a file or directory, with the help of getfattr.

  • Requires that extended attributes are enabled on the target filesystem.

Requirements

The below requirements are needed on the host that executes this module.

  • getfattr

Parameters

Parameter

Comments

follow

boolean

If true, dereferences symlinks and retrieves the attributes of the symlink target, otherwise retrieves the attributes of the symlink itself.

Choices:

  • false

  • true ← (default)

key

string

The name of a specific extended attribute to retrieve.

The value of namespace is prepended to it, unless namespace is an empty string, or namespace=user and key already starts with user..

If not set, all the extended attributes in namespace are retrieved.

namespace

string

Namespace of the extended attributes.

When key is not set, only the attributes in this namespace are returned. If set to an empty string, the attributes of all namespaces are returned.

Default: "user"

path

path / required

The full path of the file or directory to retrieve the extended attributes from.

Attributes

Attribute

Support

Description

check_mode

Support: full

This action does not modify state.

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: N/A

This action does not modify state.

Returns details on what has changed (or possibly needs changing in check_mode), when in diff mode.

See Also

See also

community.general.xattr

Manage user defined extended attributes.

C(getfattr) command manual page

Manual page for the command.

Examples

- name: Obtain the extended attributes of /etc/foo.conf
  community.general.xattr_info:
    path: /etc/foo.conf
  register: result

- name: List the names of the extended attributes of /etc/foo.conf
  ansible.builtin.debug:
    msg: "{{ result.xattr.keys() }}"

- name: Obtain the value of the key 'user.foo'
  community.general.xattr_info:
    path: /etc/foo.conf
    key: foo
  register: result

- name: Obtain the value of the key 'trusted.glusterfs.volume-id'
  community.general.xattr_info:
    path: /mnt/bricks/brick1
    namespace: trusted
    key: glusterfs.volume-id
  register: result

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

xattr

dictionary

The extended attributes, mapping their full names to their values.

Text values are returned without the surrounding quotes, binary values are returned encoded as by getfattr.

When key is set and the attribute does not exist, an empty dictionary is returned.

Returned: success

Sample: {"user.binary": "0sAP8=", "user.empty": "", "user.foo": "bar"}

Authors

  • Alexei Znamensky (@russoz)