Repository: ansible-collections/community.general

Issue:
Unable to set `bool` value in Xfce4 configuration
### Summary

I'm trying to set the bool value `/general/SaveOnExit` in `xfce4-session` to `false`. Ansible says it performs this change successfully, but the value remains unchanged after running the task.

### Issue Type

Bug Report

### Component Name

community.general.xfconf

### Ansible Version

```console (paste below)
ansible [core 2.13.2]
  config file = None
  configured module search path = ['/home/oliver/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/oliver/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/oliver/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/oliver/.local/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 3.1.2
  libyaml = True
```


### Community.general Version

```console (paste below)
# /home/oliver/.local/lib/python3.9/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 5.3.0  
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed

```
_empty_

### OS / Environment

Debian 11 Xfce4

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- name: Don't save session on exit
  community.general.xfconf:
    channel: xfce4-session
    property: /general/SaveOnExit
    value_type: bool
    value: "false"
```


### Expected Results

I expected that the "Save session for future logins" option in the logout dialog is disabled by default. More technically, I expect `xfconf-query -c xfce4-session -p /general/SaveOnExit` to return `false`.

### Actual Results

Whenever I run the above task, it will indicate that it _changed_ the value. But when I check the value, it's unchanged.

When I manually execute the module, after retaining it with `ANSIBLE_KEEP_REMOTE_FILES=1`, I always get the exact some output, no matter how often I run it. It always says it changed the value from `true` to `false`, but subsequent checks clearly indicate the value is unchanged.
```shell
$ python3 AnsiballZ_xfconf.py execute

{"changed": true, "channel": "xfce4-session", "property": "/general/SaveOnExit", "value": "false", "previous_value": "true", "type": "bool", "is_array": false, "failed": false, "invocation": {"module_args": {"channel": "xfce4-session", "property": "/general/SaveOnExit", "value_type": ["bool"], "value": ["false"], "state": "present", "force_array": false, "disable_facts": true}}}
```

Additionally, if I just use a `ansible.builtin.command: xfconf-query -c xfce4-session -p /general/SaveOnExit -t bool -s false -n` instead, I get my resulting behavior and the value is instantly changed.

Sadly I don't understand enough of Ansible yet to see how things could be going wrong from here.

### Code of Conduct

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


Discussion:
Files identified in the description:
* [`plugins/modules/system/xfconf.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/system/xfconf.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 @jbenden @russoz
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I can reproduce this. For me, the command run by the module is `['/usr/bin/xfconf-query', '--channel', 'xfce4-session', '--property', '/general/SaveOnExit', '--create', '--type', 'bool', '--set', 'False']`. Note the `False` instead of `false`.

Adding `value = 'true' if value else 'false'` as line 18 of plugins/module_utils/xfconf.py solves the problem for me. I think https://github.com/ansible-collections/community.general/commit/8ba3d9474055450fce493f1b707ae707df144dbd introduced this problem.
#5007 should fix this.
Awesome! Thanks a lot.

I was wondering about the bool handling, because I saw some examples online use `"false"` (like in my code) and not `False`. I was trying a couple different approaches in that area, but I have very little experience with Python and didn't really know what I was doing.

Either way, could you let me know how you were able to pull the final CLI argument list from it? I was trying to mess with the code to get to it myself, but didn't have enough understanding of it.
> Either way, could you let me know how you were able to pull the final CLI argument list from it? I was trying to mess with the code to get to it myself, but didn't have enough understanding of it.

I'm sure @russoz knows a better way to do this, I simply used a cheap `print()` style way: insert `import q; q.q(self.cmd)` into plugins/module_utils/cmd_runner.py (before the `module.run_command`) (using the [q package](https://pypi.org/project/q/)).
hi @oliversalzburg thanks for reporting the bug and thanks @felixfontein for quickly pinning down a fix for it. After this PR goes through, I will submit another one adding a test case that will pick on that problem - I have tested it against main and Felix's branch, getting failure and success respectively.

About seeing the resulting command line, I think I made a snafu over time: there used to be a resulting variable from the module giving that information but I believe that was removed in that same commit. I should come up with yet another PR fixing that and checking for its existence and value in the unit tests.

Resolving patch:
diff --git a/plugins/module_utils/xfconf.py b/plugins/module_utils/xfconf.py
--- a/plugins/module_utils/xfconf.py
+++ b/plugins/module_utils/xfconf.py
@@ -14,7 +14,7 @@ def _values_fmt(values, value_types):
     result = []
     for value, value_type in zip(values, value_types):
         if value_type == 'bool':
-            value = boolean(value)
+            value = 'true' if boolean(value) else 'false'
         result.extend(['--type', '{0}'.format(value_type), '--set', '{0}'.format(value)])
     return result
 


Test patch: