mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
fix WARNING log when launching ad hoc command
This commit is contained in:
@@ -34,7 +34,7 @@ from awx.main.models.mixins import ResourceMixin, TaskManagerUnifiedJobMixin
|
|||||||
from awx.main.utils import (
|
from awx.main.utils import (
|
||||||
decrypt_field, _inventory_updates,
|
decrypt_field, _inventory_updates,
|
||||||
copy_model_by_class, copy_m2m_relationships,
|
copy_model_by_class, copy_m2m_relationships,
|
||||||
get_type_for_model
|
get_type_for_model, parse_yaml_or_json
|
||||||
)
|
)
|
||||||
from awx.main.redact import UriCleaner, REPLACE_STR
|
from awx.main.redact import UriCleaner, REPLACE_STR
|
||||||
from awx.main.consumers import emit_channel_notification
|
from awx.main.consumers import emit_channel_notification
|
||||||
@@ -878,21 +878,13 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def handle_extra_data(self, extra_data):
|
def handle_extra_data(self, extra_data):
|
||||||
if hasattr(self, 'extra_vars'):
|
if hasattr(self, 'extra_vars') and extra_data:
|
||||||
extra_vars = {}
|
try:
|
||||||
if isinstance(extra_data, dict):
|
extra_data_dict = parse_yaml_or_json(extra_data, silent_failure=False)
|
||||||
extra_vars = extra_data
|
except Exception as e:
|
||||||
elif extra_data is None:
|
logger.warn("Exception deserializing extra vars: " + str(e))
|
||||||
return
|
|
||||||
else:
|
|
||||||
if extra_data == "":
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
extra_vars = json.loads(extra_data)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn("Exception deserializing extra vars: " + str(e))
|
|
||||||
evars = self.extra_vars_dict
|
evars = self.extra_vars_dict
|
||||||
evars.update(extra_vars)
|
evars.update(extra_data_dict)
|
||||||
self.update_fields(extra_vars=json.dumps(evars))
|
self.update_fields(extra_vars=json.dumps(evars))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -581,7 +581,7 @@ def cache_list_capabilities(page, prefetch_list, model, user):
|
|||||||
obj.capabilities_cache[display_method] = True
|
obj.capabilities_cache[display_method] = True
|
||||||
|
|
||||||
|
|
||||||
def parse_yaml_or_json(vars_str):
|
def parse_yaml_or_json(vars_str, silent_failure=True):
|
||||||
'''
|
'''
|
||||||
Attempt to parse a string with variables, and if attempt fails,
|
Attempt to parse a string with variables, and if attempt fails,
|
||||||
return an empty dictionary.
|
return an empty dictionary.
|
||||||
@@ -595,7 +595,9 @@ def parse_yaml_or_json(vars_str):
|
|||||||
vars_dict = yaml.safe_load(vars_str)
|
vars_dict = yaml.safe_load(vars_str)
|
||||||
assert isinstance(vars_dict, dict)
|
assert isinstance(vars_dict, dict)
|
||||||
except (yaml.YAMLError, TypeError, AttributeError, AssertionError):
|
except (yaml.YAMLError, TypeError, AttributeError, AssertionError):
|
||||||
vars_dict = {}
|
if silent_failure:
|
||||||
|
return {}
|
||||||
|
raise
|
||||||
return vars_dict
|
return vars_dict
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user