Provide type for boolean module parameters

Instead of inserting 'True' and 'False' into Ansible's BOOLEANS
constants, designate the parameters as a 'bool' type.
ansible.module_utils.basic will downcase and handle ensuring the
variables are cast to booleans.

Change-Id: I2fc70a90df5cca76b49fc21adee59350173157d9
This commit is contained in:
Jimmy McCrory 2016-05-31 14:02:40 -07:00
parent e8dec55732
commit a72d40ef8a
4 changed files with 5 additions and 18 deletions

View File

@ -222,10 +222,9 @@ def main():
image_url=dict(required=False), image_url=dict(required=False),
image_container_format=dict(required=False), image_container_format=dict(required=False),
image_disk_format=dict(required=False), image_disk_format=dict(required=False),
image_is_public=dict(required=False, choices=BOOLEANS), image_is_public=dict(required=False, type='bool'),
api_version=dict(default='1', required=False, choices=['1', '2']), api_version=dict(default='1', required=False, choices=['1', '2']),
insecure=dict(default=False, required=False, insecure=dict(default=False, required=False, type='bool')
choices=BOOLEANS + ['True', 'False'])
), ),
supports_check_mode=False supports_check_mode=False
) )

View File

@ -1334,7 +1334,7 @@ def main():
insecure=dict( insecure=dict(
default=False, default=False,
required=False, required=False,
choices=BOOLEANS + ['True', 'False'] type='bool'
), ),
return_code=dict( return_code=dict(
type='str', type='str',

View File

@ -429,8 +429,7 @@ def main():
router_name=dict(required=False), router_name=dict(required=False),
external_gateway_info=dict(required=False), external_gateway_info=dict(required=False),
tenant_id=dict(required=False), tenant_id=dict(required=False),
insecure=dict(default=False, required=False, insecure=dict(default=False, required=False, type='bool'),
choices=BOOLEANS + ['True', 'False']),
allocation_pools=dict(required=False) allocation_pools=dict(required=False)
), ),
supports_check_mode=False supports_check_mode=False

View File

@ -220,11 +220,6 @@ class ProviderNetworksParsing(object):
def main(): def main():
# Add in python True False
BOOLEANS.extend(['False', 'True'])
BOOLEANS_TRUE.append('True')
BOOLEANS_FALSE.append('False')
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
provider_networks=dict( provider_networks=dict(
@ -232,7 +227,7 @@ def main():
required=True required=True
), ),
is_metal=dict( is_metal=dict(
choices=BOOLEANS, type='bool',
default='false' default='false'
), ),
bind_prefix=dict( bind_prefix=dict(
@ -245,12 +240,6 @@ def main():
) )
try: try:
is_metal = module.params.get('is_metal')
if is_metal in BOOLEANS_TRUE:
module.params['is_metal'] = True
else:
module.params['is_metal'] = False
pnp = ProviderNetworksParsing(module=module) pnp = ProviderNetworksParsing(module=module)
pnp.load_networks( pnp.load_networks(
provider_networks=module.params.get('provider_networks'), provider_networks=module.params.get('provider_networks'),