1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 06:51:10 +03:00

Add support for processing extra vars that come in string or object form. Small bug fixes for extra var corner cases in workflow nodes.

This commit is contained in:
mabashian 2019-08-21 13:32:28 -04:00
parent 4747be7014
commit 531a7b2c05
3 changed files with 30 additions and 8 deletions

View File

@ -26,10 +26,23 @@ function PromptService (Empty, $filter) {
hasDefaultExtraVars = _.get(params, 'launchConf.defaults.extra_vars');
if(hasCurrentExtraVars && hasDefaultExtraVars) {
extraVars = jsyaml.safeDump(_.merge(jsyaml.safeLoad(params.launchConf.defaults.extra_vars), params.currentValues.extra_data));
let currentExtraVars = {};
let defaultExtraVars = {};
if (typeof params.currentValues.extra_data === 'object') {
currentExtraVars = params.currentValues.extra_data;
} else if (typeof params.currentValues.extra_data === 'string') {
currentExtraVars = jsyaml.safeDump(params.currentValues.extra_data);
}
if (typeof params.launchConf.defaults.extra_vars === 'object') {
defaultExtraVars = params.launchConf.defaults.extra_vars;
} else if (typeof params.launchConf.defaults.extra_vars === 'string') {
defaultExtraVars = jsyaml.safeLoad(params.launchConf.defaults.extra_vars);
}
extraVars = '---\n' + jsyaml.safeDump(_.merge(defaultExtraVars, currentExtraVars));
} else if(hasCurrentExtraVars) {
if (typeof params.currentValues.extra_data === 'object') {
extraVars = jsyaml.safeDump(params.currentValues.extra_data);
extraVars = '---\n' + jsyaml.safeDump(params.currentValues.extra_data);
} else if (typeof params.currentValues.extra_data === 'string') {
extraVars = params.currentValues.extra_data;
}

View File

@ -328,13 +328,19 @@ export default ['$scope', 'TemplatesService', 'JobTemplateModel', 'PromptService
let processed = PromptService.processSurveyQuestions({
surveyQuestions: surveyQuestionRes.data.spec,
extra_data: _.cloneDeep($scope.nodeConfig.node.originalNodeObject.extra_data)
extra_data: jsyaml.safeLoad(prompts.variables.value)
});
$scope.missingSurveyValue = processed.missingSurveyValue;
$scope.extraVars = (processed.extra_data === '' || _.isEmpty(processed.extra_data)) ? '---' : '---\n' + jsyaml.safeDump(processed.extra_data);
// PromptService.processSurveyQuestions will strip the survey answers out of the extra
// vars so we should update the prompt value
prompts.variables = {
value: $scope.extraVars
};
$scope.nodeConfig.node.promptData = $scope.promptData = {
launchConf: launchConf,
launchOptions: launchOptions,

View File

@ -100,12 +100,15 @@ export default ['$scope', 'TemplatesService',
}
if (_.has(node, 'promptData.extraVars')) {
const formVars = node.promptData.extraVars;
const formVarsJSON = typeof formVars === 'string' ? jsyaml.safeLoad(formVars) : formVars;
if (_.get(node, 'promptData.launchConf.defaults.extra_vars')) {
const defaultVars = jsyaml.safeLoad(node.promptData.launchConf.defaults.extra_vars);
const defaultVars = node.promptData.launchConf.defaults.extra_vars;
const defaultVarsJSON = typeof defaultVars === 'string' ? jsyaml.safeLoad(defaultVars) : defaultVars;
// Only include extra vars that differ from the template default vars
_.forOwn(node.promptData.extraVars, (value, key) => {
if (!defaultVars[key] || defaultVars[key] !== value) {
_.forOwn(formVarsJSON, (value, key) => {
if (!defaultVarsJSON[key] || defaultVarsJSON[key] !== value) {
sendableNodeData.extra_data[key] = value;
}
});
@ -113,8 +116,8 @@ export default ['$scope', 'TemplatesService',
delete sendableNodeData.extra_data;
}
} else {
if (_.has(node, 'promptData.extraVars') && !_.isEmpty(node.promptData.extraVars)) {
sendableNodeData.extra_data = node.promptData.extraVars;
if (_.has(node, 'promptData.extraVars') && !_.isEmpty(formVarsJSON)) {
sendableNodeData.extra_data = formVarsJSON;
}
}
}