diff --git a/changelogs/fragments/11645-xfconf-bool.yml b/changelogs/fragments/11645-xfconf-bool.yml new file mode 100644 index 0000000000..4947194479 --- /dev/null +++ b/changelogs/fragments/11645-xfconf-bool.yml @@ -0,0 +1,2 @@ +bugfixes: + - xfconf - representation of boolean properties was not consistent between Python and ``xfconf-query``, leading to broken idempotency (https://github.com/ansible-collections/community.general/pull/11645). diff --git a/plugins/modules/xfconf.py b/plugins/modules/xfconf.py index f4e214e2cf..e4212e06be 100644 --- a/plugins/modules/xfconf.py +++ b/plugins/modules/xfconf.py @@ -176,6 +176,8 @@ version: version_added: 10.2.0 """ +from ansible.module_utils.parsing.convert_bool import boolean + from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper from ansible_collections.community.general.plugins.module_utils.xfconf import xfconf_runner, get_xfconf_version @@ -238,9 +240,6 @@ class XFConfProperty(StateModuleHelper): self.vars.value = None def state_present(self): - # stringify all values - in the CLI they will all be happy strings anyway - # and by doing this here the rest of the code can be agnostic to it - self.vars.value = [str(v) for v in self.vars.value] value_type = self.vars.value_type values_len = len(self.vars.value) @@ -253,6 +252,14 @@ class XFConfProperty(StateModuleHelper): # or complain if lists' lengths are different self.do_raise('Number of elements in "value" and "value_type" must be the same') + # stringify all values - in the CLI they will all be happy strings anyway + # and by doing this here the rest of the code can be agnostic to it + # bool values are normalized to 'true'/'false' to match xfconf-query output format + self.vars.value = [ + ("true" if boolean(v) else "false") if vt == "bool" else str(v) + for v, vt in zip(self.vars.value, value_type) + ] + # calculates if it is an array self.vars.is_array = \ bool(self.vars.force_array) or \ diff --git a/tests/unit/plugins/modules/test_xfconf.yaml b/tests/unit/plugins/modules/test_xfconf.yaml index 14d59eae3d..aaf937ecf1 100644 --- a/tests/unit/plugins/modules/test_xfconf.yaml +++ b/tests/unit/plugins/modules/test_xfconf.yaml @@ -79,6 +79,36 @@ test_cases: rc: 0 out: '' err: '' + - id: test_property_set_property_bool_same_value + input: + channel: xfce4-session + property: /general/SaveOnExit + state: present + value_type: bool + value: false + output: + changed: false + previous_value: 'false' + type: bool + value: 'false' + version: 4.18.1 + mocks: + run_command: + - command: [/testbin/xfconf-query, --version] + environ: *env-def + rc: 0 + out: *version-output + err: '' + - command: [/testbin/xfconf-query, --channel, xfce4-session, --property, /general/SaveOnExit] + environ: *env-def + rc: 0 + out: "false\n" + err: '' + - command: [/testbin/xfconf-query, --channel, xfce4-session, --property, /general/SaveOnExit, --create, --type, bool, --set, 'false'] + environ: *env-def + rc: 0 + out: '' + err: '' - id: test_property_set_property_bool_false input: channel: xfce4-session @@ -90,7 +120,7 @@ test_cases: changed: true previous_value: 'true' type: bool - value: 'False' + value: 'false' version: 4.18.1 mocks: run_command: