From 320276f8ca07fee849505609727aee7a81176f27 Mon Sep 17 00:00:00 2001 From: beeankha Date: Mon, 3 Feb 2020 10:47:04 -0500 Subject: [PATCH] Remove JSONDecodeError exception, fix tower_host variable issue --- awx_collection/plugins/modules/tower_host.py | 9 +++++---- awx_collection/plugins/modules/tower_settings.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/awx_collection/plugins/modules/tower_host.py b/awx_collection/plugins/modules/tower_host.py index d115267f1b..c416e020d6 100644 --- a/awx_collection/plugins/modules/tower_host.py +++ b/awx_collection/plugins/modules/tower_host.py @@ -114,10 +114,10 @@ def main(): with open(filename, 'r') as f: variables = f.read() - # Attempt to lookup the related items the user specified (these will fail the module if not found) + # Attempt to look up the related items the user specified (these will fail the module if not found) inventory_id = module.resolve_name_to_id('inventories', inventory) - # Attempt to lookup host based on the provided name and org ID + # Attempt to look up host based on the provided name and inventory ID host = module.get_one('hosts', **{ 'data': { 'name': name, @@ -129,14 +129,15 @@ def main(): host_fields = { 'name': new_name if new_name else name, 'description': description, - 'inventory': inventory_id + 'inventory': inventory_id, + 'enabled': enabled } if state == 'absent': # If the state was absent we can let the module delete it if needed, the module will handle exiting from this module.delete_if_needed(host) elif state == 'present': - # If the state was present we can let the module build or update the existing host, this will return on its own + # If the state was present and we can let the module build or update the existing host, this will return on its own module.create_or_update_if_needed(host, host_fields, endpoint='hosts', item_type='host') diff --git a/awx_collection/plugins/modules/tower_settings.py b/awx_collection/plugins/modules/tower_settings.py index f96cdcf61a..8b73b1a212 100644 --- a/awx_collection/plugins/modules/tower_settings.py +++ b/awx_collection/plugins/modules/tower_settings.py @@ -79,7 +79,6 @@ EXAMPLES = ''' from ..module_utils.tower_api import TowerModule from json import loads -from json.decoder import JSONDecodeError import re @@ -110,7 +109,8 @@ def main(): new_value = value try: new_value = loads(value) - except JSONDecodeError: + except ValueError: + # JSONDecodeError only available on Python 3.5+ # Attempt to deal with old tower_cli array types if ',' in value: new_value = re.split(r",\s+", new_value)