mirror of
https://github.com/ansible/awx.git
synced 2026-03-17 08:57:33 -02:30
AC-1068 all variables (inventory, template, group, host) are now sorted alphabetically
This commit is contained in:
@@ -19,7 +19,7 @@ angular.module('VariablesHelper', ['Utilities'])
|
|||||||
will attempt to load via jsyaml.safeLoad() and return a YAML document using jsyaml.safeDump(). In all cases
|
will attempt to load via jsyaml.safeLoad() and return a YAML document using jsyaml.safeDump(). In all cases
|
||||||
a YAML document is returned.
|
a YAML document is returned.
|
||||||
**/
|
**/
|
||||||
.factory('ParseVariableString', ['$log', 'ProcessErrors', function ($log, ProcessErrors) {
|
.factory('ParseVariableString', ['$log', 'ProcessErrors', 'SortVariables', function ($log, ProcessErrors, SortVariables) {
|
||||||
return function (variables) {
|
return function (variables) {
|
||||||
var result = "---", json_obj;
|
var result = "---", json_obj;
|
||||||
if (typeof variables === 'string') {
|
if (typeof variables === 'string') {
|
||||||
@@ -28,10 +28,11 @@ angular.module('VariablesHelper', ['Utilities'])
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
json_obj = JSON.parse(variables);
|
json_obj = JSON.parse(variables);
|
||||||
|
json_obj = SortVariables(json_obj);
|
||||||
result = jsyaml.safeDump(json_obj);
|
result = jsyaml.safeDump(json_obj);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
$log.info('Attempt to parse extra_vars as JSON faild. Attempting to parse as YAML');
|
$log.info('Attempt to parse extra_vars as JSON failed. Attempting to parse as YAML');
|
||||||
try {
|
try {
|
||||||
json_obj = jsyaml.safeLoad(variables);
|
json_obj = jsyaml.safeLoad(variables);
|
||||||
result = jsyaml.safeDump(json_obj);
|
result = jsyaml.safeDump(json_obj);
|
||||||
@@ -50,7 +51,8 @@ angular.module('VariablesHelper', ['Utilities'])
|
|||||||
else {
|
else {
|
||||||
// convert object to yaml
|
// convert object to yaml
|
||||||
try {
|
try {
|
||||||
result = jsyaml.safeDump(variables);
|
json_obj = SortVariables(variables);
|
||||||
|
result = jsyaml.safeDump(json_obj);
|
||||||
}
|
}
|
||||||
catch(e3) {
|
catch(e3) {
|
||||||
ProcessErrors(null, variables, e3.message, null, { hdr: 'Error!',
|
ProcessErrors(null, variables, e3.message, null, { hdr: 'Error!',
|
||||||
@@ -113,4 +115,54 @@ angular.module('VariablesHelper', ['Utilities'])
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
}])
|
||||||
|
|
||||||
|
.factory('SortVariables', [ function() {
|
||||||
|
return function(variableObj) {
|
||||||
|
var newObj;
|
||||||
|
function sortIt(objToSort) {
|
||||||
|
var i, keys = Object.keys(objToSort), newObj = {};
|
||||||
|
keys = keys.sort();
|
||||||
|
for (i=0; i < keys.length; i++) {
|
||||||
|
if (typeof objToSort[keys[i]] === 'object' && !Array.isArray(objToSort[keys[i]])) {
|
||||||
|
newObj[keys[i]] = sortIt(objToSort[keys[i]]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newObj[keys[i]] = objToSort[keys[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
newObj = sortIt(variableObj);
|
||||||
|
return newObj;
|
||||||
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user