mirror of
https://github.com/ansible/awx.git
synced 2024-10-30 05:25:29 +03:00
Remove JSONDecodeError exception, fix tower_host variable issue
This commit is contained in:
parent
f89061da41
commit
320276f8ca
@ -114,10 +114,10 @@ def main():
|
|||||||
with open(filename, 'r') as f:
|
with open(filename, 'r') as f:
|
||||||
variables = f.read()
|
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)
|
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', **{
|
host = module.get_one('hosts', **{
|
||||||
'data': {
|
'data': {
|
||||||
'name': name,
|
'name': name,
|
||||||
@ -129,14 +129,15 @@ def main():
|
|||||||
host_fields = {
|
host_fields = {
|
||||||
'name': new_name if new_name else name,
|
'name': new_name if new_name else name,
|
||||||
'description': description,
|
'description': description,
|
||||||
'inventory': inventory_id
|
'inventory': inventory_id,
|
||||||
|
'enabled': enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# 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)
|
module.delete_if_needed(host)
|
||||||
elif state == 'present':
|
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')
|
module.create_or_update_if_needed(host, host_fields, endpoint='hosts', item_type='host')
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@ EXAMPLES = '''
|
|||||||
|
|
||||||
from ..module_utils.tower_api import TowerModule
|
from ..module_utils.tower_api import TowerModule
|
||||||
from json import loads
|
from json import loads
|
||||||
from json.decoder import JSONDecodeError
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
@ -110,7 +109,8 @@ def main():
|
|||||||
new_value = value
|
new_value = value
|
||||||
try:
|
try:
|
||||||
new_value = loads(value)
|
new_value = loads(value)
|
||||||
except JSONDecodeError:
|
except ValueError:
|
||||||
|
# JSONDecodeError only available on Python 3.5+
|
||||||
# Attempt to deal with old tower_cli array types
|
# Attempt to deal with old tower_cli array types
|
||||||
if ',' in value:
|
if ',' in value:
|
||||||
new_value = re.split(r",\s+", new_value)
|
new_value = re.split(r",\s+", new_value)
|
||||||
|
Loading…
Reference in New Issue
Block a user