debconf: handle boolean value representation consistently (#83601)

* lift code that normalizes value type for boolean vtype to cover both
  branches of conditional.
* remove obsolete and incomplete conversion of type in set_selection.

Fixes: #83594
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
pull/83630/head
Peter A. Bigot 4 months ago committed by GitHub
parent 4408b2c3e1
commit c904bffc7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
bugfixes:
- debconf - fix normalization of value representation for boolean vtypes in new packages (https://github.com/ansible/ansible/issues/83594)

@ -173,8 +173,6 @@ def set_selection(module, pkg, question, vtype, value, unseen):
if unseen: if unseen:
cmd.append('-u') cmd.append('-u')
if vtype == 'boolean':
value = value.lower()
data = ' '.join([pkg, question, vtype, value]) data = ' '.join([pkg, question, vtype, value])
return module.run_command(cmd, data=data) return module.run_command(cmd, data=data)
@ -209,15 +207,17 @@ def main():
if vtype is None or value is None: if vtype is None or value is None:
module.fail_json(msg="when supplying a question you must supply a valid vtype and value") module.fail_json(msg="when supplying a question you must supply a valid vtype and value")
# ensure we compare booleans supplied to the way debconf sees them (true/false strings)
if vtype == 'boolean':
value = to_text(value).lower()
# if question doesn't exist, value cannot match # if question doesn't exist, value cannot match
if question not in prev: if question not in prev:
changed = True changed = True
else: else:
existing = prev[question] existing = prev[question]
# ensure we compare booleans supplied to the way debconf sees them (true/false strings)
if vtype == 'boolean': if vtype == 'boolean':
value = to_text(value).lower()
existing = to_text(prev[question]).lower() existing = to_text(prev[question]).lower()
elif vtype == 'password': elif vtype == 'password':
existing = get_password_value(module, pkg, question, vtype) existing = get_password_value(module, pkg, question, vtype)

@ -146,6 +146,32 @@
- not debconf_multiselect_test_idem_4.changed - not debconf_multiselect_test_idem_4.changed
- '"Invalid value provided" in debconf_multiselect_test_idem_4.msg' - '"Invalid value provided" in debconf_multiselect_test_idem_4.msg'
- name: Boolean vtype from boolean value
debconf:
name: libnns-ldap
question: libnss-ldapd/clean_nsswitch
vtype: boolean
value: true
register: debconf_bool_test_bool_1
- name: validate results for boolean vtype from boolean value
assert:
that:
- debconf_bool_test_bool_1.changed
- name: Boolean vtype from string value
debconf:
name: libnns-ldap
question: libnss-ldapd/clean_nsswitch
vtype: boolean
value: "FALSE"
register: debconf_bool_test_bool_2
- name: validate results for boolean vtype from string value
assert:
that:
- debconf_bool_test_bool_2.changed
always: always:
- name: uninstall debconf-utils - name: uninstall debconf-utils
apt: apt:
@ -153,4 +179,4 @@
state: absent state: absent
when: debconf_utils_deb_install is changed when: debconf_utils_deb_install is changed
when: ansible_distribution in ('Ubuntu', 'Debian') when: ansible_distribution in ('Ubuntu', 'Debian')

Loading…
Cancel
Save