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:
parent
4747be7014
commit
531a7b2c05
@ -26,10 +26,23 @@ function PromptService (Empty, $filter) {
|
|||||||
hasDefaultExtraVars = _.get(params, 'launchConf.defaults.extra_vars');
|
hasDefaultExtraVars = _.get(params, 'launchConf.defaults.extra_vars');
|
||||||
|
|
||||||
if(hasCurrentExtraVars && hasDefaultExtraVars) {
|
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) {
|
} else if(hasCurrentExtraVars) {
|
||||||
if (typeof params.currentValues.extra_data === 'object') {
|
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') {
|
} else if (typeof params.currentValues.extra_data === 'string') {
|
||||||
extraVars = params.currentValues.extra_data;
|
extraVars = params.currentValues.extra_data;
|
||||||
}
|
}
|
||||||
|
@ -328,13 +328,19 @@ export default ['$scope', 'TemplatesService', 'JobTemplateModel', 'PromptService
|
|||||||
|
|
||||||
let processed = PromptService.processSurveyQuestions({
|
let processed = PromptService.processSurveyQuestions({
|
||||||
surveyQuestions: surveyQuestionRes.data.spec,
|
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.missingSurveyValue = processed.missingSurveyValue;
|
||||||
|
|
||||||
$scope.extraVars = (processed.extra_data === '' || _.isEmpty(processed.extra_data)) ? '---' : '---\n' + jsyaml.safeDump(processed.extra_data);
|
$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 = {
|
$scope.nodeConfig.node.promptData = $scope.promptData = {
|
||||||
launchConf: launchConf,
|
launchConf: launchConf,
|
||||||
launchOptions: launchOptions,
|
launchOptions: launchOptions,
|
||||||
|
@ -100,12 +100,15 @@ export default ['$scope', 'TemplatesService',
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_.has(node, 'promptData.extraVars')) {
|
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')) {
|
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
|
// Only include extra vars that differ from the template default vars
|
||||||
_.forOwn(node.promptData.extraVars, (value, key) => {
|
_.forOwn(formVarsJSON, (value, key) => {
|
||||||
if (!defaultVars[key] || defaultVars[key] !== value) {
|
if (!defaultVarsJSON[key] || defaultVarsJSON[key] !== value) {
|
||||||
sendableNodeData.extra_data[key] = value;
|
sendableNodeData.extra_data[key] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -113,8 +116,8 @@ export default ['$scope', 'TemplatesService',
|
|||||||
delete sendableNodeData.extra_data;
|
delete sendableNodeData.extra_data;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_.has(node, 'promptData.extraVars') && !_.isEmpty(node.promptData.extraVars)) {
|
if (_.has(node, 'promptData.extraVars') && !_.isEmpty(formVarsJSON)) {
|
||||||
sendableNodeData.extra_data = node.promptData.extraVars;
|
sendableNodeData.extra_data = formVarsJSON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user