Repository: ansible-collections/community.general

Issue:
xattr module does not correctly handle values with non-printable characters
### Summary

The xattr module fails to retrieve extended attributes with values containing non-printable characters.

### Issue Type

Bug Report

### Component Name

xattr

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.11.6] 
  config file = /home/user/git/inm/infra/playbooks/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/virtualenvs/ansible/lib/python3.8/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/virtualenvs/ansible/bin/ansible
  python version = 3.8.10 (default, Jun  2 2021, 10:49:15) [GCC 10.3.0]
  jinja version = 3.0.2
  libyaml = True
```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general
# /home/user/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 3.0.0  

# /home/user/virtualenvs/ansible/lib/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 3.8.1  

```


### Configuration

_No response_

### OS / Environment

Ubuntu 20.04

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---

- hosts: all
  tasks:
    - file:
        path: /tmp/baz
        state: touch
    - xattr:
        path: /tmp/baz
        namespace: user
        key: foobar
        value: 0sAAECAwQFBgcICQ==
        state: present
    - xattr:
        path: /tmp/baz
```


### Expected Results

The module xattr should get the extended attribute value without error

### Actual Results

```console
PLAY [all] *********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [file] ********************************************************************************************************************************************************************************************************************************
changed: [127.0.0.1] => {"changed": true, "dest": "/tmp/baz", "gid": 1000, "group": "user", "mode": "0644", "owner": "user", "size": 0, "state": "file", "uid": 1000}

TASK [xattr] *******************************************************************************************************************************************************************************************************************************
changed: [127.0.0.1] => {"changed": true, "msg": "user.foobar set to 0sAAECAwQFBgcICQ==", "xattr": {}}

TASK [xattr] *******************************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: too many values to unpack (expected 2)
fatal: [127.0.0.1]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/user/.ansible/tmp/ansible-tmp-1636396276.8214228-674630-247893767396378/AnsiballZ_xattr.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/home/user/.ansible/tmp/ansible-tmp-1636396276.8214228-674630-247893767396378/AnsiballZ_xattr.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/user/.ansible/tmp/ansible-tmp-1636396276.8214228-674630-247893767396378/AnsiballZ_xattr.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.xattr', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.xattr', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/run/user/1000/tmp/ansible_xattr_payload_q522e3yn/ansible_xattr_payload.zip/ansible_collections/community/general/plugins/modules/xattr.py\", line 234, in <module>\n  File \"/run/user/1000/tmp/ansible_xattr_payload_q522e3yn/ansible_xattr_payload.zip/ansible_collections/community/general/plugins/modules/xattr.py\", line 227, in main\n  File \"/run/user/1000/tmp/ansible_xattr_payload_q522e3yn/ansible_xattr_payload.zip/ansible_collections/community/general/plugins/modules/xattr.py\", line 121, in get_xattr\n  File \"/run/user/1000/tmp/ansible_xattr_payload_q522e3yn/ansible_xattr_payload.zip/ansible_collections/community/general/plugins/modules/xattr.py\", line 160, in _run_xattr\nValueError: too many values to unpack (expected 2)\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************
127.0.0.1                  : ok=3    changed=2    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
```

### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/files/xattr.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/files/xattr.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @bcoca
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
FYI: the 3.0.0 version of the collection is rather old and hides the 3.8.1 version coming with Ansible itself. You should uninstall it so that the latest version is used, and not an old version. (Just delete /home/user/.ansible/collections/ansible_collections/community/general for that.)
Thanks for the advice, I've done just that but unfortunately I can still reproduce the issue.

```console
$ ansible-galaxy collection list community.general

# /home/user/virtualenvs/ansible/lib/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 3.8.1  
```
```console
PLAY [all] *********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [file] ********************************************************************************************************************************************************************************************************************************
changed: [127.0.0.1] => {"changed": true, "dest": "/tmp/baz", "gid": 1000, "group": "user", "mode": "0644", "owner": "user", "size": 0, "state": "file", "uid": 1000}

TASK [xattr] *******************************************************************************************************************************************************************************************************************************
changed: [127.0.0.1] => {"changed": true, "msg": "user.foobar set to 0sAAECAwQFBgcICQ==", "xattr": {}}

TASK [xattr] *******************************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: too many values to unpack (expected 2)
fatal: [127.0.0.1]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/user/.ansible/tmp/ansible-tmp-1636407050.2278454-688175-280942939148364/AnsiballZ_xattr.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/home/user/.ansible/tmp/ansible-tmp-1636407050.2278454-688175-280942939148364/AnsiballZ_xattr.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/user/.ansible/tmp/ansible-tmp-1636407050.2278454-688175-280942939148364/AnsiballZ_xattr.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.xattr', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.xattr', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/run/user/1000/tmp/ansible_xattr_payload_aolhod10/ansible_xattr_payload.zip/ansible_collections/community/general/plugins/modules/xattr.py\", line 235, in <module>\n  File \"/run/user/1000/tmp/ansible_xattr_payload_aolhod10/ansible_xattr_payload.zip/ansible_collections/community/general/plugins/modules/xattr.py\", line 228, in main\n  File \"/run/user/1000/tmp/ansible_xattr_payload_aolhod10/ansible_xattr_payload.zip/ansible_collections/community/general/plugins/modules/xattr.py\", line 122, in get_xattr\n  File \"/run/user/1000/tmp/ansible_xattr_payload_aolhod10/ansible_xattr_payload.zip/ansible_collections/community/general/plugins/modules/xattr.py\", line 161, in _run_xattr\nValueError: too many values to unpack (expected 2)\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************
127.0.0.1                  : ok=3    changed=2    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
```

Resolving patch:
diff --git a/plugins/modules/files/xattr.py b/plugins/modules/files/xattr.py
--- a/plugins/modules/files/xattr.py
+++ b/plugins/modules/files/xattr.py
@@ -158,7 +158,7 @@ def _run_xattr(module, cmd, check_rc=True):
         if line.startswith('#') or line == '':
             pass
         elif '=' in line:
-            (key, val) = line.split('=')
+            (key, val) = line.split('=', 1)
             result[key] = val.strip('"')
         else:
             result[line] = ''


Test patch: