@ -121,6 +121,13 @@ EXAMPLES = r"""
value : " {{ site_passphrase }} "
value : " {{ site_passphrase }} "
vtype : password
vtype : password
no_log : True
no_log : True
- name : Set seen flag to true for locales
ansible . builtin . debconf :
name : locales
question : locales / default_environment_locale
vtype : seen
value : ' true '
"""
"""
RETURN = r """ # """
RETURN = r """ # """
@ -162,12 +169,17 @@ def get_selections(module, pkg):
module . fail_json ( msg = err )
module . fail_json ( msg = err )
selections = { }
selections = { }
seen = [ ] # list of seen questions
for line in out . splitlines ( ) :
for line in out . splitlines ( ) :
( key , value ) = line . split ( ' : ' , 1 )
( key , value ) = line . split ( ' : ' , 1 )
selections [ key . strip ( ' * ' ) . strip ( ) ] = value . strip ( )
if key . startswith ( ' * ' ) :
key = key . strip ( ' * ' ) . strip ( )
seen . append ( key )
selections [ key ] = value . strip ( )
else :
selections [ key . strip ( ) ] = value . strip ( )
return selections
return selections , seen
def set_selection ( module , pkg , question , vtype , value , unseen ) :
def set_selection ( module , pkg , question , vtype , value , unseen ) :
@ -201,7 +213,7 @@ def main():
value = module . params [ " value " ]
value = module . params [ " value " ]
unseen = module . params [ " unseen " ]
unseen = module . params [ " unseen " ]
prev = get_selections ( module , pkg )
prev , seen_list = get_selections ( module , pkg )
changed = False
changed = False
msg = " "
msg = " "
@ -211,7 +223,7 @@ def main():
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)
# ensure we compare booleans supplied to the way debconf sees them (true/false strings)
if vtype == ' boolean ' :
if vtype in ( ' boolean ' , ' seen ' ) :
value = to_text ( value ) . lower ( )
value = to_text ( value ) . lower ( )
# if question doesn't exist, value cannot match
# if question doesn't exist, value cannot match
@ -230,6 +242,13 @@ def main():
except TypeError as exc :
except TypeError as exc :
module . fail_json ( msg = " Invalid value provided for ' multiselect ' : %s " % to_native ( exc ) )
module . fail_json ( msg = " Invalid value provided for ' multiselect ' : %s " % to_native ( exc ) )
existing = sorted ( [ i . strip ( ) for i in existing . split ( " , " ) ] )
existing = sorted ( [ i . strip ( ) for i in existing . split ( " , " ) ] )
elif vtype == ' seen ' :
# vtype seen is a special case where we only care if the question is seen or not
if question in seen_list :
# if the question is seen, the value must be true
existing = ' true '
else :
existing = ' false '
if value != existing :
if value != existing :
changed = True
changed = True