diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index 6877083daf..147a8bcbd9 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -594,8 +594,22 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP data.extra_vars === "" || data.extra_vars === null) { $scope.variables = "---"; } else { - json_obj = JSON.parse(data.extra_vars); - $scope.variables = jsyaml.safeDump(json_obj); + $scope.variables = '---'; + try { + json_obj = JSON.parse(data.extra_vars); + $scope.variables = jsyaml.safeDump(json_obj); + } + catch (e) { + $log.info('Attempt to parse extra_vars as JSON faild. Attempting to parse as YAML'); + try { + json_obj = jsyaml.safeLoad(data.extra_vars); + $scope.variables = jsyaml.safeDump(json_obj); + } + catch(e2) { + ProcessErrors($scope, data.extra_vars, e2.message, null, { hdr: 'Error!', + msg: 'Attempts to parse variables as JSON and YAML failed. Last attempt returned: ' + e2.message }); + } + } } master.variables = $scope.variables; } diff --git a/awx/ui/static/js/controllers/Jobs.js b/awx/ui/static/js/controllers/Jobs.js index 018313c4ed..2f71835c75 100644 --- a/awx/ui/static/js/controllers/Jobs.js +++ b/awx/ui/static/js/controllers/Jobs.js @@ -379,8 +379,22 @@ function JobsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, J data.extra_vars === "" || data.extra_vars === null) { $scope.variables = "---"; } else { - json_obj = JSON.parse(data.extra_vars); - $scope.variables = jsyaml.safeDump(json_obj); + $scope.variables = '---'; + try { + json_obj = JSON.parse(data.extra_vars); + $scope.variables = jsyaml.safeDump(json_obj); + } + catch (e) { + $log.info('Attempt to parse extra_vars as JSON faild. Attempting to parse as YAML'); + try { + json_obj = jsyaml.safeLoad(data.extra_vars); + $scope.variables = jsyaml.safeDump(json_obj); + } + catch(e2) { + ProcessErrors($scope, data.extra_vars, e2.message, null, { hdr: 'Error!', + msg: 'Attempts to parse variables as JSON and YAML failed. Last attempt returned: ' + e2.message }); + } + } } } if (JobTemplateForm.fields[fld].type === 'lookup' && data.summary_fields[JobTemplateForm.fields[fld].sourceModel]) { diff --git a/awx/ui/static/lib/ansible/Utilities.js b/awx/ui/static/lib/ansible/Utilities.js index a200acc90c..53e09d3f52 100644 --- a/awx/ui/static/lib/ansible/Utilities.js +++ b/awx/ui/static/lib/ansible/Utilities.js @@ -133,10 +133,13 @@ angular.module('Utilities', ['RestServices', 'Utilities']) return function (scope, data, status, form, defaultMsg) { var field, fieldErrors, msg; Wait('stop'); - if ($AnsibleConfig.debug_mode && console) { - console.log('Debug status: ' + status); - console.log('Debug data: '); - console.log(data); + if ($AnsibleConfig.debug_mode) { + $log.debug('Debug status: ' + status); + $log.debug('Debug data: '); + $log.debug(data); + if (defaultMsg.msg) { + $log.debug('Debug: ' + defaultMsg.msg); + } } if (status === 403) { msg = 'The API responded with a 403 Access Denied error. ';