summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/debconf.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/modules/debconf.py')
-rw-r--r--lib/ansible/modules/debconf.py49
1 files changed, 14 insertions, 35 deletions
diff --git a/lib/ansible/modules/debconf.py b/lib/ansible/modules/debconf.py
index 5ff14029..32f0000c 100644
--- a/lib/ansible/modules/debconf.py
+++ b/lib/ansible/modules/debconf.py
@@ -27,13 +27,13 @@ attributes:
platforms: debian
notes:
- This module requires the command line debconf tools.
- - Several questions have to be answered (depending on the package).
+ - A number of questions have to be answered (depending on the package).
Use 'debconf-show <package>' on any Debian or derivative with the package
installed to see questions/settings available.
- Some distros will always record tasks involving the setting of passwords as changed. This is due to debconf-get-selections masking passwords.
- - It is highly recommended to add C(no_log=True) to the task while handling sensitive information using this module.
+ - It is highly recommended to add I(no_log=True) to task while handling sensitive information using this module.
- The debconf module does not reconfigure packages, it just updates the debconf database.
- An additional step is needed (typically with C(notify) if debconf makes a change)
+ An additional step is needed (typically with I(notify) if debconf makes a change)
to reconfigure the package and apply the changes.
debconf is extensively used for pre-seeding configuration prior to installation
rather than modifying configurations.
@@ -46,7 +46,7 @@ notes:
- The main issue is that the C(<package>.config reconfigure) step for many packages
will first reset the debconf database (overriding changes made by this module) by
checking the on-disk configuration. If this is the case for your package then
- dpkg-reconfigure will effectively ignore changes made by debconf.
+ dpkg-reconfigure will effectively ignore changes made by debconf.
- However as dpkg-reconfigure only executes the C(<package>.config) step if the file
exists, it is possible to rename it to C(/var/lib/dpkg/info/<package>.config.ignore)
before executing C(dpkg-reconfigure -f noninteractive <package>) and then restore it.
@@ -69,8 +69,8 @@ options:
vtype:
description:
- The type of the value supplied.
- - It is highly recommended to add C(no_log=True) to task while specifying O(vtype=password).
- - V(seen) was added in Ansible 2.2.
+ - It is highly recommended to add I(no_log=True) to task while specifying I(vtype=password).
+ - C(seen) was added in Ansible 2.2.
type: str
choices: [ boolean, error, multiselect, note, password, seen, select, string, text, title ]
value:
@@ -124,32 +124,10 @@ EXAMPLES = r'''
RETURN = r'''#'''
-from ansible.module_utils.common.text.converters import to_text
+from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
-def get_password_value(module, pkg, question, vtype):
- getsel = module.get_bin_path('debconf-get-selections', True)
- cmd = [getsel]
- rc, out, err = module.run_command(cmd)
- if rc != 0:
- module.fail_json(msg="Failed to get the value '%s' from '%s'" % (question, pkg))
-
- desired_line = None
- for line in out.split("\n"):
- if line.startswith(pkg):
- desired_line = line
- break
-
- if not desired_line:
- module.fail_json(msg="Failed to find the value '%s' from '%s'" % (question, pkg))
-
- (dpkg, dquestion, dvtype, dvalue) = desired_line.split()
- if dquestion == question and dvtype == vtype:
- return dvalue
- return ''
-
-
def get_selections(module, pkg):
cmd = [module.get_bin_path('debconf-show', True), pkg]
rc, out, err = module.run_command(' '.join(cmd))
@@ -173,7 +151,10 @@ def set_selection(module, pkg, question, vtype, value, unseen):
cmd.append('-u')
if vtype == 'boolean':
- value = value.lower()
+ if value == 'True':
+ value = 'true'
+ elif value == 'False':
+ value = 'false'
data = ' '.join([pkg, question, vtype, value])
return module.run_command(cmd, data=data)
@@ -212,6 +193,7 @@ def main():
if question not in prev:
changed = True
else:
+
existing = prev[question]
# ensure we compare booleans supplied to the way debconf sees them (true/false strings)
@@ -219,9 +201,6 @@ def main():
value = to_text(value).lower()
existing = to_text(prev[question]).lower()
- if vtype == 'password':
- existing = get_password_value(module, pkg, question, vtype)
-
if value != existing:
changed = True
@@ -236,12 +215,12 @@ def main():
prev = {question: prev[question]}
else:
prev[question] = ''
-
- diff_dict = {}
if module._diff:
after = prev.copy()
after.update(curr)
diff_dict = {'before': prev, 'after': after}
+ else:
+ diff_dict = {}
module.exit_json(changed=changed, msg=msg, current=curr, previous=prev, diff=diff_dict)