fixes as per feedback

pull/5361/head
Brian Coca 11 years ago
parent 35980ef329
commit 453d473728

@ -45,7 +45,7 @@ options:
required: false required: false
default: null default: null
aliases: ['question', 'selection'] aliases: ['question', 'selection']
type: vtype:
description: description:
- The type of the value supplied - The type of the value supplied
required: false required: false
@ -57,7 +57,7 @@ options:
- Value to set the configuration to - Value to set the configuration to
required: false required: false
default: null default: null
aliases: ['awnser'] aliases: ['answer']
unseen: unseen:
description: description:
- Do not set 'seen' flag when pre-seeding - Do not set 'seen' flag when pre-seeding
@ -76,33 +76,33 @@ debconf: name=locales setting='locales/default_environment_locale' value=fr_FR.U
debconf: name=locales setting='locales/locales_to_be_generated value='en_US.UTF-8 UTF-8, fr_FR.UTF-8 UTF-8' debconf: name=locales setting='locales/locales_to_be_generated value='en_US.UTF-8 UTF-8, fr_FR.UTF-8 UTF-8'
# Accept oracle license # Accept oracle license
debconf: names='oracle-java7-installer' question='shared/accepted-oracle-license-v1-1' value='true' type='select' debconf: names='oracle-java7-installer' question='shared/accepted-oracle-license-v1-1' value='true' vtype='select'
''' '''
def get_selections(module, pkg): def get_selections(module, pkg):
cmd = [module.get_bin_path('debconf-show', True), pkg] cmd = [module.get_bin_path('debconf-show', True), pkg]
rc, out, err = module.run_command(' '.join(cmd)) rc, out, err = module.run_command(' '.join(cmd))
if rc == 0: if rc != 0:
selections = {}
for line in out.splitlines():
#if not line.startswith('*'): # only awnsered
# continue
(key, value) = line.split(':')
selections[ key.strip('*').strip() ] = value.strip()
return selections
else:
module.fail_json(msg=err) module.fail_json(msg=err)
selections = {}
for line in out.splitlines():
(key, value) = line.split(':')
selections[ key.strip('*').strip() ] = value.strip()
return selections
def set_selection(module, pkg, question, type, value, unseen): def set_selection(module, pkg, question, vtype, value, unseen):
awnser = [ question ] answer = [ question ]
if 'type': if 'vtype':
awnser.append(type) answer.append(vtype)
awnser.append(value) answer.append(value)
data = ' '.join(awnser) data = ' '.join(answer)
setsel = module.get_bin_path('debconf-set-selections', True) setsel = module.get_bin_path('debconf-set-selections', True)
cmd = ["echo '%s %s' |" % (pkg, data), setsel] cmd = ["echo '%s %s' |" % (pkg, data), setsel]
@ -117,7 +117,7 @@ def main():
argument_spec = dict( argument_spec = dict(
name = dict(required=True, aliases=['pkg'], type='str'), name = dict(required=True, aliases=['pkg'], type='str'),
setting = dict(required=False, aliases=['question', 'selection'], type='str'), setting = dict(required=False, aliases=['question', 'selection'], type='str'),
type = dict(required=False, type='str', choices=['string', 'boolean', 'select', 'multiselect', 'note', 'text', 'password', 'title']), vtype = dict(required=False, type='str', choices=['string', 'boolean', 'select', 'multiselect', 'note', 'text', 'password', 'title']),
value= dict(required=False, type='str'), value= dict(required=False, type='str'),
unseen = dict(required=False, type='bool'), unseen = dict(required=False, type='bool'),
), ),
@ -127,7 +127,7 @@ def main():
#TODO: enable passing array of optionas and/or debconf file from get-selections dump #TODO: enable passing array of optionas and/or debconf file from get-selections dump
pkg = module.params["name"] pkg = module.params["name"]
question = module.params["setting"] question = module.params["setting"]
type = module.params["type"] vtype = module.params["vtype"]
value = module.params["value"] value = module.params["value"]
unseen = module.params["unseen"] unseen = module.params["unseen"]
@ -143,7 +143,7 @@ def main():
if changed: if changed:
if not module.check_mode: if not module.check_mode:
rc, msg, e = set_selection(module, pkg, question, type, value, unseen) rc, msg, e = set_selection(module, pkg, question, vtype, value, unseen)
if rc: if rc:
module.fail_json(msg=e) module.fail_json(msg=e)
@ -157,6 +157,5 @@ def main():
module.exit_json(changed=changed, msg=msg, current=prev) module.exit_json(changed=changed, msg=msg, current=prev)
# this is magic, see lib/ansible/module_common.py # import module snippets
#<<INCLUDE_ANSIBLE_MODULE_COMMON>> from ansible.module_utils.basic import *
main()

Loading…
Cancel
Save