Allow value to be bool where 'yes'/'no' are in choices (#2593)
* Changed type of 'details' argument to bool on ecs_service_facts module. * Changed type of 'autostart' argument to bool on virt_* modules. * Changed types of 'autoconnect' and 'stp' argument to bool on nmcli module. ('create_connection_bridge(self)' and 'modify_connection_bridge(self)' are not implemented yet?) * Added conversion of 'value' argument when 'vtype' is boolean on debconf module.
This commit is contained in:
parent
cb13575186
commit
5fbb0de36f
5 changed files with 30 additions and 21 deletions
|
@ -55,7 +55,7 @@ EXAMPLES = '''
|
||||||
- ecs_service_facts:
|
- ecs_service_facts:
|
||||||
cluster: test-cluster
|
cluster: test-cluster
|
||||||
service: console-test-service
|
service: console-test-service
|
||||||
details: "true"
|
details: true
|
||||||
|
|
||||||
# Basic listing example
|
# Basic listing example
|
||||||
- ecs_service_facts:
|
- ecs_service_facts:
|
||||||
|
@ -201,7 +201,7 @@ def main():
|
||||||
|
|
||||||
argument_spec = ec2_argument_spec()
|
argument_spec = ec2_argument_spec()
|
||||||
argument_spec.update(dict(
|
argument_spec.update(dict(
|
||||||
details=dict(required=False, choices=['true', 'false'] ),
|
details=dict(required=False, type='bool', default=False ),
|
||||||
cluster=dict(required=False, type='str' ),
|
cluster=dict(required=False, type='str' ),
|
||||||
service=dict(required=False, type='str' )
|
service=dict(required=False, type='str' )
|
||||||
))
|
))
|
||||||
|
@ -214,9 +214,7 @@ def main():
|
||||||
if not HAS_BOTO3:
|
if not HAS_BOTO3:
|
||||||
module.fail_json(msg='boto3 is required.')
|
module.fail_json(msg='boto3 is required.')
|
||||||
|
|
||||||
show_details = False
|
show_details = module.params.get('details', False)
|
||||||
if 'details' in module.params and module.params['details'] == 'true':
|
|
||||||
show_details = True
|
|
||||||
|
|
||||||
task_mgr = EcsServiceManager(module)
|
task_mgr = EcsServiceManager(module)
|
||||||
if show_details:
|
if show_details:
|
||||||
|
|
|
@ -534,16 +534,16 @@ def core(module):
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Command %s not recognized" % basecmd)
|
module.fail_json(msg="Command %s not recognized" % basecmd)
|
||||||
|
|
||||||
if autostart:
|
if autostart is not None:
|
||||||
if not name:
|
if not name:
|
||||||
module.fail_json(msg = "state change requires a specified name")
|
module.fail_json(msg = "state change requires a specified name")
|
||||||
|
|
||||||
res['changed'] = False
|
res['changed'] = False
|
||||||
if autostart == 'yes':
|
if autostart:
|
||||||
if not v.get_autostart(name):
|
if not v.get_autostart(name):
|
||||||
res['changed'] = True
|
res['changed'] = True
|
||||||
res['msg'] = v.set_autostart(name, True)
|
res['msg'] = v.set_autostart(name, True)
|
||||||
elif autostart == 'no':
|
else:
|
||||||
if v.get_autostart(name):
|
if v.get_autostart(name):
|
||||||
res['changed'] = True
|
res['changed'] = True
|
||||||
res['msg'] = v.set_autostart(name, False)
|
res['msg'] = v.set_autostart(name, False)
|
||||||
|
@ -562,7 +562,7 @@ def main():
|
||||||
command = dict(choices=ALL_COMMANDS),
|
command = dict(choices=ALL_COMMANDS),
|
||||||
uri = dict(default='qemu:///system'),
|
uri = dict(default='qemu:///system'),
|
||||||
xml = dict(),
|
xml = dict(),
|
||||||
autostart = dict(choices=['yes', 'no'])
|
autostart = dict(type='bool')
|
||||||
),
|
),
|
||||||
supports_check_mode = True
|
supports_check_mode = True
|
||||||
)
|
)
|
||||||
|
|
|
@ -629,16 +629,16 @@ def core(module):
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Command %s not recognized" % basecmd)
|
module.fail_json(msg="Command %s not recognized" % basecmd)
|
||||||
|
|
||||||
if autostart:
|
if autostart is not None:
|
||||||
if not name:
|
if not name:
|
||||||
module.fail_json(msg = "state change requires a specified name")
|
module.fail_json(msg = "state change requires a specified name")
|
||||||
|
|
||||||
res['changed'] = False
|
res['changed'] = False
|
||||||
if autostart == 'yes':
|
if autostart:
|
||||||
if not v.get_autostart(name):
|
if not v.get_autostart(name):
|
||||||
res['changed'] = True
|
res['changed'] = True
|
||||||
res['msg'] = v.set_autostart(name, True)
|
res['msg'] = v.set_autostart(name, True)
|
||||||
elif autostart == 'no':
|
else:
|
||||||
if v.get_autostart(name):
|
if v.get_autostart(name):
|
||||||
res['changed'] = True
|
res['changed'] = True
|
||||||
res['msg'] = v.set_autostart(name, False)
|
res['msg'] = v.set_autostart(name, False)
|
||||||
|
@ -657,7 +657,7 @@ def main():
|
||||||
command = dict(choices=ALL_COMMANDS),
|
command = dict(choices=ALL_COMMANDS),
|
||||||
uri = dict(default='qemu:///system'),
|
uri = dict(default='qemu:///system'),
|
||||||
xml = dict(),
|
xml = dict(),
|
||||||
autostart = dict(choices=['yes', 'no']),
|
autostart = dict(type='bool'),
|
||||||
mode = dict(choices=ALL_MODES),
|
mode = dict(choices=ALL_MODES),
|
||||||
),
|
),
|
||||||
supports_check_mode = True
|
supports_check_mode = True
|
||||||
|
|
|
@ -514,6 +514,12 @@ class Nmcli(object):
|
||||||
return setting_list
|
return setting_list
|
||||||
# print ""
|
# print ""
|
||||||
|
|
||||||
|
def bool_to_string(self, boolean):
|
||||||
|
if boolean:
|
||||||
|
return "yes"
|
||||||
|
else:
|
||||||
|
return "no"
|
||||||
|
|
||||||
def list_connection_info(self):
|
def list_connection_info(self):
|
||||||
# Ask the settings service for the list of connections it provides
|
# Ask the settings service for the list of connections it provides
|
||||||
bus=dbus.SystemBus()
|
bus=dbus.SystemBus()
|
||||||
|
@ -602,7 +608,7 @@ class Nmcli(object):
|
||||||
cmd.append(self.gw6)
|
cmd.append(self.gw6)
|
||||||
if self.autoconnect is not None:
|
if self.autoconnect is not None:
|
||||||
cmd.append('autoconnect')
|
cmd.append('autoconnect')
|
||||||
cmd.append(self.autoconnect)
|
cmd.append(self.bool_to_string(self.autoconnect))
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
def modify_connection_team(self):
|
def modify_connection_team(self):
|
||||||
|
@ -631,7 +637,7 @@ class Nmcli(object):
|
||||||
cmd.append(self.dns6)
|
cmd.append(self.dns6)
|
||||||
if self.autoconnect is not None:
|
if self.autoconnect is not None:
|
||||||
cmd.append('autoconnect')
|
cmd.append('autoconnect')
|
||||||
cmd.append(self.autoconnect)
|
cmd.append(self.bool_to_string(self.autoconnect))
|
||||||
# Can't use MTU with team
|
# Can't use MTU with team
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
@ -704,7 +710,7 @@ class Nmcli(object):
|
||||||
cmd.append(self.gw6)
|
cmd.append(self.gw6)
|
||||||
if self.autoconnect is not None:
|
if self.autoconnect is not None:
|
||||||
cmd.append('autoconnect')
|
cmd.append('autoconnect')
|
||||||
cmd.append(self.autoconnect)
|
cmd.append(self.bool_to_string(self.autoconnect))
|
||||||
if self.mode is not None:
|
if self.mode is not None:
|
||||||
cmd.append('mode')
|
cmd.append('mode')
|
||||||
cmd.append(self.mode)
|
cmd.append(self.mode)
|
||||||
|
@ -751,7 +757,7 @@ class Nmcli(object):
|
||||||
cmd.append(self.dns6)
|
cmd.append(self.dns6)
|
||||||
if self.autoconnect is not None:
|
if self.autoconnect is not None:
|
||||||
cmd.append('autoconnect')
|
cmd.append('autoconnect')
|
||||||
cmd.append(self.autoconnect)
|
cmd.append(self.bool_to_string(self.autoconnect))
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
def create_connection_bond_slave(self):
|
def create_connection_bond_slave(self):
|
||||||
|
@ -820,7 +826,7 @@ class Nmcli(object):
|
||||||
cmd.append(self.gw6)
|
cmd.append(self.gw6)
|
||||||
if self.autoconnect is not None:
|
if self.autoconnect is not None:
|
||||||
cmd.append('autoconnect')
|
cmd.append('autoconnect')
|
||||||
cmd.append(self.autoconnect)
|
cmd.append(self.bool_to_string(self.autoconnect))
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
def modify_connection_ethernet(self):
|
def modify_connection_ethernet(self):
|
||||||
|
@ -855,7 +861,7 @@ class Nmcli(object):
|
||||||
cmd.append(self.mtu)
|
cmd.append(self.mtu)
|
||||||
if self.autoconnect is not None:
|
if self.autoconnect is not None:
|
||||||
cmd.append('autoconnect')
|
cmd.append('autoconnect')
|
||||||
cmd.append(self.autoconnect)
|
cmd.append(self.bool_to_string(self.autoconnect))
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
def create_connection_bridge(self):
|
def create_connection_bridge(self):
|
||||||
|
@ -964,7 +970,7 @@ def main():
|
||||||
# Parsing argument file
|
# Parsing argument file
|
||||||
module=AnsibleModule(
|
module=AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
autoconnect=dict(required=False, default=None, choices=['yes', 'no'], type='str'),
|
autoconnect=dict(required=False, default=None, type='bool'),
|
||||||
state=dict(required=True, choices=['present', 'absent'], type='str'),
|
state=dict(required=True, choices=['present', 'absent'], type='str'),
|
||||||
conn_name=dict(required=True, type='str'),
|
conn_name=dict(required=True, type='str'),
|
||||||
master=dict(required=False, default=None, type='str'),
|
master=dict(required=False, default=None, type='str'),
|
||||||
|
@ -987,7 +993,7 @@ def main():
|
||||||
mtu=dict(required=False, default=None, type='str'),
|
mtu=dict(required=False, default=None, type='str'),
|
||||||
mac=dict(required=False, default=None, type='str'),
|
mac=dict(required=False, default=None, type='str'),
|
||||||
# bridge specific vars
|
# bridge specific vars
|
||||||
stp=dict(required=False, default='yes', choices=['yes', 'no'], type='str'),
|
stp=dict(required=False, default=True, type='bool'),
|
||||||
priority=dict(required=False, default="128", type='str'),
|
priority=dict(required=False, default="128", type='str'),
|
||||||
slavepriority=dict(required=False, default="32", type='str'),
|
slavepriority=dict(required=False, default="32", type='str'),
|
||||||
forwarddelay=dict(required=False, default="15", type='str'),
|
forwarddelay=dict(required=False, default="15", type='str'),
|
||||||
|
|
|
@ -108,6 +108,11 @@ def set_selection(module, pkg, question, vtype, value, unseen):
|
||||||
if unseen:
|
if unseen:
|
||||||
cmd.append('-u')
|
cmd.append('-u')
|
||||||
|
|
||||||
|
if vtype == 'boolean':
|
||||||
|
if value == 'True':
|
||||||
|
value = 'true'
|
||||||
|
elif value == 'False':
|
||||||
|
value = 'false'
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue