1
0
Fork 0
mirror of https://github.com/mmumshad/ansible-playable.git synced 2025-03-09 23:38:54 +00:00

Identify task module names from modules list

This commit is contained in:
Mumshad Mannambeth 2017-06-12 23:49:17 -04:00
parent a71d1109a8
commit 02ab635fe7
10 changed files with 361 additions and 194 deletions

View file

@ -20,11 +20,17 @@ import 'ansi-to-html';
import 'angular-markdown-directive'; import 'angular-markdown-directive';
import 'ng-tags-input';
import 'angular-loading-bar';
import treecontrol from 'angular-tree-control'; import treecontrol from 'angular-tree-control';
import 'angular-tree-control/css/tree-control-attribute.css'; import 'angular-tree-control/css/tree-control-attribute.css';
import 'angular-tree-control/css/tree-control.css'; import 'angular-tree-control/css/tree-control.css';
import 'ng-tags-input/build/ng-tags-input.min.css';
import { import {
routeConfig routeConfig
} from './app.config'; } from './app.config';
@ -102,7 +108,7 @@ angular.module('app2App', [ngCookies, ngResource, ngSanitize, uiRouter, uiBootst
// Filters // Filters
dictToKeyValueArray, dictToKeyValueArraySimple, keyValueArrayToDict, keyValueArrayToArray, addDotInKey, removeDotInKey, json2yaml, dictToKeyValueArray, dictToKeyValueArraySimple, keyValueArrayToDict, keyValueArrayToArray, addDotInKey, removeDotInKey, json2yaml,
// Directives // Directives
complexVar, tasks, treecontrol, 'btford.markdown' complexVar, tasks, treecontrol, 'btford.markdown', 'ngTagsInput', 'angular-loading-bar'
]) ])
.config(routeConfig) .config(routeConfig)

View file

@ -35,6 +35,8 @@ export class DesignerComponent {
Projects.selectedProject = $scope.selectedProject; Projects.selectedProject = $scope.selectedProject;
$scope.listOfInventoryFiles(); $scope.listOfInventoryFiles();
$scope.$broadcast('projectLoaded'); $scope.$broadcast('projectLoaded');
// Refresh modules list on project load
ansible.getAnsibleModules();
}) })
}; };

View file

@ -1,47 +1,56 @@
<div style="padding:15px;"> <div style="padding:15px;">
<div class="row"> <div class="row">
<div class="col-md-2"> <div class="col-md-2">
<div class="panel"> <select class="form-control" ng-model="selectedProjectID" ng-change="projectSelected(selectedProjectID)" ng-options="project._id as project.name for project in projects">
</select>
<div ng-if="selectedProject.ansibleVersion" class="hint">
Ansible Version:{{selectedProject.ansibleVersion}}
</div>
<br>
<select class="form-control" ng-model="selectedInventoryFileName" ng-options="inventoryFile as inventoryFile for inventoryFile in inventoryFiles" ng-change="inventoryFileSelected(selectedInventoryFileName)">
</select>
<div ng-if="selectedProject.ansibleVersion" class="hint">
An inventory file to work with
</div>
<br>
<div class="btn-group-vertical" style="width:100%" role="group" aria-label="...">
<button class="btn btn-default" ui-sref="designer.inventory">Inventory</button>
<button class="btn btn-default" ui-sref="designer.playbook">Playbooks</button>
<button class="btn btn-default" ui-sref="designer.roles">Roles</button>
<button class="btn btn-default" ui-sref="designer.file_browser">File Browser</button>
</div>
<!--<div class="panel">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Projects</div> <div class="panel-heading">Projects</div>
<div class="panel-body"> <div class="panel-body">
<select class="form-control" ng-model="selectedProjectID" ng-change="projectSelected(selectedProjectID)" ng-options="project._id as project.name for project in projects">
</select>
<div ng-if="selectedProject.ansibleVersion" class="hint">
Ansible Version:{{selectedProject.ansibleVersion}}
</div>
</div> </div>
</div> </div>
</div> </div>
-->
<div class="panel"> <!--<div class="panel">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Inventory Files</div> <div class="panel-heading">Inventory Files</div>
<div class="panel-body"> <div class="panel-body">
<select class="form-control" ng-model="selectedInventoryFileName" ng-options="inventoryFile as inventoryFile for inventoryFile in inventoryFiles" ng-change="inventoryFileSelected(selectedInventoryFileName)">
</select>
<div ng-if="selectedProject.ansibleVersion" class="hint">
An inventory file to work with
</div>
</div> </div>
</div> </div>
</div> </div>-->
<div class="panel"> <!--<div class="panel">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Menu</div> <div class="panel-heading">Menu</div>
<div class="panel-body"> <div class="panel-body">
<div class="btn-group-vertical" role="group" aria-label="...">
<button class="btn btn-default" ui-sref="designer.inventory">Inventory</button>
<button class="btn btn-default" ui-sref="designer.playbook">Playbooks</button>
<button class="btn btn-default" ui-sref="designer.roles">Roles</button>
<button class="btn btn-default" ui-sref="designer.file_browser">File Browser</button>
</div>
</div> </div>
</div> </div>
</div> </div>-->
<div class="alert alert-danger" ng-if="err_msg">{{err_msg}}</div> <div class="alert alert-danger" ng-if="err_msg">{{err_msg}}</div>
</div> </div>

View file

@ -55,8 +55,9 @@ export function newTaskController($window, $scope, $sce, $uibModal, ansi2html, a
selectedTask = angular.copy(selectedTask); selectedTask = angular.copy(selectedTask);
$scope.newTask = selectedTask; $scope.newTask = selectedTask;
if(selectedTask.tags)$scope.newTask.tags = $scope.newTask.tags.join(','); if(selectedTask.tags)$scope.newTask.tags = $scope.newTask.tags.join(',');
var module = $scope.getModuleFromTask(selectedTask); $scope.getModuleFromTask(selectedTask, module => {
$scope.getModuleDescription(module,true) $scope.getModuleDescription(module,true)
});
} }
}, function(response){ }, function(response){
@ -180,66 +181,68 @@ export function newTaskController($window, $scope, $sce, $uibModal, ansi2html, a
* @param task - Single task object containing task properties * @param task - Single task object containing task properties
* @returns {{}} * @returns {{}}
*/ */
$scope.getModuleFromTask = function(task){ $scope.getModuleFromTask = function(task, successCallback){
var moduleObject = {}; var moduleObject = {};
$scope.local_action = false; $scope.local_action = false;
var task_properties = null; var task_properties = null;
var module = ansible.getModuleFromTask(task); ansible.getModuleFromTask(task, module => {
if(module === 'include'){
if(module === 'include'){ module = null;
module = null; task.tags = task.include.replace(/.*tags=(.*)/,"$1")
task.tags = task.include.replace(/.*tags=(.*)/,"$1") return;
return; }else if(module === 'local_action'){
}else if(module === 'local_action'){ $scope.local_action = true;
$scope.local_action = true; module = task.local_action.module;
module = task.local_action.module; task_properties = task.local_action;
task_properties = task.local_action; delete task_properties.module;
delete task_properties.module; }else{
}else{ task_properties = task[module];
task_properties = task[module];
}
angular.forEach($scope.modules, function(item,index) {
if(item.name == module){
moduleObject = item;
$scope.newTask.module = item;
} }
angular.forEach($scope.modules, function(item,index) {
if(item.name == module){
moduleObject = item;
$scope.newTask.module = item;
}
});
if(!(moduleObject && moduleObject.name)){
$scope.err_msg = "Unable to find module " + module + " in Ansible controller";
return
}
//moduleObject.name = module;
moduleObject.variables = [];
if(typeof task_properties == "string"){
moduleObject.variables.push({'name':'free_form','value':task_properties});
var re = /\b(\w+)=\s*([^=]*\S)\b\s*(?=\w+=|$)/g;
var m;
while ((m = re.exec(task_properties)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
// View your result using the m-variable.
// eg m[0] etc.
var k=m[1];
var v=m[2];
moduleObject.variables.push({'name':k,'value':v})
}
}else if(typeof task_properties == "object"){
angular.forEach(task_properties,function(value,key){
this.push({'name':key,'value':value,'complexValue':value})
},moduleObject.variables)
}
successCallback(moduleObject);
}); });
if(!(moduleObject && moduleObject.name)){
$scope.err_msg = "Unable to find module " + module + " in Ansible controller";
return
}
//moduleObject.name = module;
moduleObject.variables = [];
if(typeof task_properties == "string"){
moduleObject.variables.push({'name':'free_form','value':task_properties});
var re = /\b(\w+)=\s*([^=]*\S)\b\s*(?=\w+=|$)/g;
var m;
while ((m = re.exec(task_properties)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
// View your result using the m-variable.
// eg m[0] etc.
var k=m[1];
var v=m[2];
moduleObject.variables.push({'name':k,'value':v})
}
}else if(typeof task_properties == "object"){
angular.forEach(task_properties,function(value,key){
this.push({'name':key,'value':value,'complexValue':value})
},moduleObject.variables)
}
return moduleObject
}; };

View file

@ -27,14 +27,15 @@ export default angular.module('webAppApp.tasks', [])
scope.tasksMetaData = []; scope.tasksMetaData = [];
angular.forEach(scope.tasksList,function(task){ angular.forEach(scope.tasksList,function(task){
var taskModule = ansible.getModuleFromTask(task); ansible.getModuleFromTask(task, taskModule => {
var taskName = task.name; var taskName = task.name;
if(taskModule === 'include'){ if(taskModule === 'include'){
taskName = task[taskModule].replace(/(.*yml) .*/,"$1") taskName = task[taskModule].replace(/(.*yml) .*/,"$1")
} }
scope.tasksMetaData.push({taskModule:taskModule,taskName:taskName,selected:false}) scope.tasksMetaData.push({taskModule:taskModule,taskName:taskName,selected:false})
});
}) })
},true); },true);

View file

@ -13,7 +13,12 @@
<td><input type="checkbox" ng-model="tasksMetaData[$index].selected"> <td><input type="checkbox" ng-model="tasksMetaData[$index].selected">
</td> </td>
<td>{{tasksMetaData[$index].taskName}}</td> <td>{{tasksMetaData[$index].taskName}}</td>
<td>{{tasksMetaData[$index].taskModule}}</td> <td ng-if="tasksMetaData[$index].taskModule">
{{tasksMetaData[$index].taskModule}}
</td>
<td ng-if="!tasksMetaData[$index].taskModule" class="warning" uib-tooltip="The module could not be identified. This may be because the module used in this task is not available in the Ansible Host. Run 'ansible-doc -l' to see if the module is available on the host">
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Unidentified
</td>
<td> <td>
<div class="btn-group"> <div class="btn-group">
<label class="btn btn-default btn-sm" ng-click="showTaskModal($index)"><span <label class="btn btn-default btn-sm" ng-click="showTaskModal($index)"><span

View file

@ -2,234 +2,372 @@
const angular = require('angular'); const angular = require('angular');
/*@ngInject*/ /*@ngInject*/
export function ansibleService($http,YAML,Projects) { export function ansibleService($http, YAML, Projects) {
// AngularJS will instantiate a singleton by calling "new" on this function // AngularJS will instantiate a singleton by calling "new" on this function
// AngularJS will instantiate a singleton by calling "new" on this function // AngularJS will instantiate a singleton by calling "new" on this function
var AnsibleService = this; var AnsibleService = this;
var uri = '/api/ansible/'; var uri = '/api/ansible/';
var emptyPlaybookContent = '---\n# Playbook File -'; var emptyPlaybookContent = '---\n# Playbook File -';
var defaultTaskProperties = ["variables","tags","name","notify","with_items","first_available_file","only_if","user","sudo","connection","when","register","ignore_errors","selected","changed_when","delegate_to","vars","poll","async","args","with_together"]; var defaultTaskProperties = ["variables", "tags", "name", "notify", "with_items", "first_available_file", "only_if", "user", "sudo", "connection", "when", "register", "ignore_errors", "selected", "changed_when", "delegate_to", "vars", "poll", "async", "args", "with_together"];
// A Cache Map of hosts and modules list. Different hosts(Ansible Engines) can have different list of modules
AnsibleService.modules = {}; AnsibleService.modules = {};
this.getAnsibleModules = function(successCallback,errorCallback,parent,refresh){ // A cache map of hosts and modules names.
if(!refresh && AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost]) AnsibleService.module_names = {};
// A local command bugger to wait for a command execution to finish, to avoid duplicate executions
AnsibleService.cmd_buffer = [];
/**
* Get Ansible Modules
* @param successCallback
* @param errorCallback
* @param parent
* @param refresh - Weather to force a refresh of list of modules from server.
* If false uses modules list from browser cache.
* @returns {*}
*/
this.getAnsibleModules = function (successCallback, errorCallback, parent, refresh) {
if (this.cmd_buffer.indexOf(Projects.selectedProject.ansibleEngine.ansibleHost) > -1) {
// We're just waiting.
setTimeout(function(){
//do what you need here
AnsibleService.getAnsibleModules(successCallback, errorCallback, parent, refresh);
}, 1000);
return;
}
if (!refresh && AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost])
return successCallback(AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost]); return successCallback(AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost]);
try{ try {
if(!refresh && JSON.parse(localStorage['modules_' + Projects.selectedProject.ansibleEngine.ansibleHost])) if (!refresh && JSON.parse(localStorage['modules_' + Projects.selectedProject.ansibleEngine.ansibleHost]))
return successCallback(JSON.parse(localStorage['modules_' + Projects.selectedProject.ansibleEngine.ansibleHost])); return successCallback(JSON.parse(localStorage['modules_' + Projects.selectedProject.ansibleEngine.ansibleHost]));
}catch(e){ } catch (e) {
//console.error(e) //console.error(e)
} }
$http.post(uri + 'modules',{ansibleEngine:Projects.selectedProject.ansibleEngine}).then(function(response){ // If not found in local browser cache, retrieve from server
AnsibleService.cmd_buffer.push(Projects.selectedProject.ansibleEngine.ansibleHost);
$http.post(uri + 'modules', {ansibleEngine: Projects.selectedProject.ansibleEngine}).then(function (response) {
var result = response.data.split('\n'); var result = response.data.split('\n');
AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost] = result.map(function(item){ AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost] = result.map(function (item) {
return {"name" : item.split(" ")[0], "description": item.split(/ (.+)?/)[1]} return {"name": item.split(" ")[0], "description": item.split(/ (.+)?/)[1]}
}); });
localStorage['modules_' + Projects.selectedProject.ansibleEngine.ansibleHost] = JSON.stringify(AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost]); AnsibleService.module_names[Projects.selectedProject.ansibleEngine.ansibleHost] = AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost].map(module => {
return module.name;
});
successCallback(AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost]) localStorage['modules_' + Projects.selectedProject.ansibleEngine.ansibleHost] = JSON.stringify(AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost]);
AnsibleService.cmd_buffer.splice(AnsibleService.cmd_buffer.indexOf(Projects.selectedProject.ansibleEngine.ansibleHost), 1)
successCallback && successCallback(AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost]);
}, errResponse => {
this.cmd_buffer.splice(this.cmd_buffer.indexOf(Projects.selectedProject.ansibleEngine.ansibleHost), 1);
errorCallback && errorCallback(errResponse)
})
};
this.getAnsibleModuleNames = function (successCallback, errorCallback, refresh) {
if (!refresh && AnsibleService.module_names[Projects.selectedProject.ansibleEngine.ansibleHost])
return successCallback(AnsibleService.module_names[Projects.selectedProject.ansibleEngine.ansibleHost]);
this.getAnsibleModules(function () {
successCallback(AnsibleService.module_names[Projects.selectedProject.ansibleEngine.ansibleHost]);
}, errorCallback, null, refresh);
},errorCallback)
}; };
this.getAnsibleModuleDescription = function(moduleName, successCallback,errorCallback,refresh){ this.getAnsibleModuleDescription = function (moduleName, successCallback, errorCallback, refresh) {
try{ try {
if(!refresh && JSON.parse(localStorage['module_description_' + Projects.selectedProject.ansibleEngine.ansibleHost + '_' + moduleName])) if (!refresh && JSON.parse(localStorage['module_description_' + Projects.selectedProject.ansibleEngine.ansibleHost + '_' + moduleName]))
return successCallback(JSON.parse(localStorage['module_description_' + Projects.selectedProject.ansibleEngine.ansibleHost + '_' + moduleName])); return successCallback(JSON.parse(localStorage['module_description_' + Projects.selectedProject.ansibleEngine.ansibleHost + '_' + moduleName]));
}catch(e){ } catch (e) {
} }
var command = 'ansible-doc ' + moduleName; var command = 'ansible-doc ' + moduleName;
if(Projects.selectedProject.ansibleEngine.customModules){ if (Projects.selectedProject.ansibleEngine.customModules) {
command = 'export ANSIBLE_LIBRARY="' + Projects.selectedProject.ansibleEngine.customModules + '"; ' + command; command = 'export ANSIBLE_LIBRARY="' + Projects.selectedProject.ansibleEngine.customModules + '"; ' + command;
} }
$http.post(uri + 'command',{ansibleEngine:Projects.selectedProject.ansibleEngine,command:command}) $http.post(uri + 'command', {ansibleEngine: Projects.selectedProject.ansibleEngine, command: command})
.then(function(response){ .then(function (response) {
localStorage['module_description_' + Projects.selectedProject.ansibleEngine.ansibleHost + '_' + moduleName] = JSON.stringify(response.data); localStorage['module_description_' + Projects.selectedProject.ansibleEngine.ansibleHost + '_' + moduleName] = JSON.stringify(response.data);
successCallback(response.data) successCallback(response.data)
},errorCallback) }, errorCallback)
}; };
this.executeAnsiblePlayBook = function(body,successCallback,errorCallback,parent){ this.executeAnsiblePlayBook = function (body, successCallback, errorCallback, parent) {
$http.post(uri + 'execute',body).then(successCallback,errorCallback) $http.post(uri + 'execute', body).then(successCallback, errorCallback)
}; };
this.executeCommand = function(command, successCallback,errorCallback){ this.executeCommand = function (command, successCallback, errorCallback) {
$http.post(uri + 'command',{command:command,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'command', {
command: command,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
this.getLogs = function(executionData,successCallback,errorCallback){ this.getLogs = function (executionData, successCallback, errorCallback) {
$http.get(uri+'logs/'+executionData._id).then(successCallback,errorCallback); $http.get(uri + 'logs/' + executionData._id).then(successCallback, errorCallback);
}; };
this.query = function(successCallback,errorCallback){ this.query = function (successCallback, errorCallback) {
$http.get(uri).then(successCallback,errorCallback); $http.get(uri).then(successCallback, errorCallback);
}; };
this.getModuleFromTask = function(task){ this.getModuleFromTask = function (task, successCallback, errorCallback) {
var module = null; var module = null;
angular.forEach(JSON.parse(angular.toJson(task)), function(value, key) { console.log("Getting module from task");
if(defaultTaskProperties.indexOf(key) < 0){
module = key
this.getAnsibleModuleNames(modules => {
angular.forEach(JSON.parse(angular.toJson(task)), (value, key) => {
if (modules.indexOf(key) > -1) {
module = key
}
});
if (module === 'include' && !task.tags && task.include.indexOf('tags') > -1) {
task.tags = task.include.replace(/.*tags=(.*)/, "$1")
} }
});
if(module === 'include' && !task.tags && task.include.indexOf('tags') > -1){ successCallback(module);
task.tags = task.include.replace(/.*tags=(.*)/,"$1")
} }, errorCallback);
return module;
}; };
// -------------------------- PROJECT ------------------------- // -------------------------- PROJECT -------------------------
this.getProjectFiles = function(successCallback,errorCallback){ this.getProjectFiles = function (successCallback, errorCallback) {
$http.post(uri + 'project/files',{ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'project/files', {ansibleEngine: Projects.selectedProject.ansibleEngine}).then(successCallback, errorCallback)
}; };
// -------------------------- PLAYBOOK ------------------------- // -------------------------- PLAYBOOK -------------------------
this.getPlaybookList = function(successCallback,errorCallback){ this.getPlaybookList = function (successCallback, errorCallback) {
$http.post(uri + 'playbook/list',{ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'playbook/list', {ansibleEngine: Projects.selectedProject.ansibleEngine}).then(successCallback, errorCallback)
}; };
this.deletePlaybook = function(playbookName,successCallback,errorCallback){ this.deletePlaybook = function (playbookName, successCallback, errorCallback) {
$http.post(uri + 'playbook/delete',{ansibleEngine:Projects.selectedProject.ansibleEngine,playbookName:playbookName}).then(successCallback,errorCallback) $http.post(uri + 'playbook/delete', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
playbookName: playbookName
}).then(successCallback, errorCallback)
}; };
this.createPlaybook = function(playbookName,playbookFileContents,successCallback,errorCallback){ this.createPlaybook = function (playbookName, playbookFileContents, successCallback, errorCallback) {
var playbookContent = playbookFileContents || (emptyPlaybookContent + playbookName); var playbookContent = playbookFileContents || (emptyPlaybookContent + playbookName);
$http.post(uri + 'playbook/create',{ansibleEngine:Projects.selectedProject.ansibleEngine,playbookName:playbookName,playbookFileContents:playbookContent}).then(successCallback,errorCallback) $http.post(uri + 'playbook/create', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
playbookName: playbookName,
playbookFileContents: playbookContent
}).then(successCallback, errorCallback)
}; };
this.readPlaybook = function(playbookName,successCallback,errorCallback){ this.readPlaybook = function (playbookName, successCallback, errorCallback) {
$http.post(uri + 'playbook/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,playbookName:playbookName}).then(successCallback,errorCallback) $http.post(uri + 'playbook/get', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
playbookName: playbookName
}).then(successCallback, errorCallback)
}; };
this.readPlaybookData = function(playbookData){ this.readPlaybookData = function (playbookData) {
return YAML.parse(playbookData) return YAML.parse(playbookData)
}; };
// -------------------------- ROLES ------------------------- // -------------------------- ROLES -------------------------
this.getRoleList = function(successCallback,errorCallback){ this.getRoleList = function (successCallback, errorCallback) {
$http.post(uri + 'roles/list',{ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'roles/list', {ansibleEngine: Projects.selectedProject.ansibleEngine}).then(successCallback, errorCallback)
}; };
this.searchRolesGalaxy = function(searchText,successCallback,errorCallback){ this.searchRolesGalaxy = function (searchText, successCallback, errorCallback) {
$http.post(uri + 'roles/search/galaxy',{searchText:searchText,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'roles/search/galaxy', {
searchText: searchText,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
this.searchRolesGithub = function(searchText,successCallback,errorCallback){ this.searchRolesGithub = function (searchText, successCallback, errorCallback) {
$http.post(uri + 'roles/search/github',{searchText:searchText,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'roles/search/github', {
searchText: searchText,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
this.createRole = function(roleName,successCallback,errorCallback,selectedRoleName){ this.createRole = function (roleName, successCallback, errorCallback, selectedRoleName) {
$http.post(uri + 'roles/create',{roleName:roleName,selectedRoleName:selectedRoleName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'roles/create', {
roleName: roleName,
selectedRoleName: selectedRoleName,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
this.importRole = function(roleType,roleNameUri,successCallback,errorCallback){ this.importRole = function (roleType, roleNameUri, successCallback, errorCallback) {
$http.post(uri + 'roles/import',{roleType:roleType,roleNameUri:roleNameUri,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'roles/import', {
roleType: roleType,
roleNameUri: roleNameUri,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
this.deleteRole = function(roleName,successCallback,errorCallback){ this.deleteRole = function (roleName, successCallback, errorCallback) {
$http.post(uri + 'roles/delete',{roleName:roleName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'roles/delete', {
roleName: roleName,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
this.getRoleFiles = function(roleName,successCallback,errorCallback){ this.getRoleFiles = function (roleName, successCallback, errorCallback) {
$http.post(uri + 'roles/files',{roleName:roleName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'roles/files', {
roleName: roleName,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
// -------------------------- FILES ------------------------- // -------------------------- FILES -------------------------
this.createFile = function(fileAbsolutePath,successCallback,errorCallback,selectedFileName){ this.createFile = function (fileAbsolutePath, successCallback, errorCallback, selectedFileName) {
$http.post(uri + 'files/create',{fileAbsolutePath:fileAbsolutePath,selectedFileName:selectedFileName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'files/create', {
fileAbsolutePath: fileAbsolutePath,
selectedFileName: selectedFileName,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
this.updateFile = function(fileAbsolutePath,fileContents,successCallback,errorCallback,selectedFileName){ this.updateFile = function (fileAbsolutePath, fileContents, successCallback, errorCallback, selectedFileName) {
$http.post(uri + 'files/update',{fileAbsolutePath:fileAbsolutePath,fileContents:fileContents,selectedFileName:selectedFileName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'files/update', {
fileAbsolutePath: fileAbsolutePath,
fileContents: fileContents,
selectedFileName: selectedFileName,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
this.deleteFile = function(fileAbsolutePath,successCallback,errorCallback,selectedFileName){ this.deleteFile = function (fileAbsolutePath, successCallback, errorCallback, selectedFileName) {
$http.post(uri + 'files/delete',{fileAbsolutePath:fileAbsolutePath,selectedFileName:selectedFileName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'files/delete', {
fileAbsolutePath: fileAbsolutePath,
selectedFileName: selectedFileName,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
// -------------------------- INVENTORY ------------------------- // -------------------------- INVENTORY -------------------------
this.getInventoryList = function(successCallback,errorCallback, projectFolder){ this.getInventoryList = function (successCallback, errorCallback, projectFolder) {
// Override project folder for other cases, such as roles // Override project folder for other cases, such as roles
var ansibleEngine = Projects.selectedProject.ansibleEngine; var ansibleEngine = Projects.selectedProject.ansibleEngine;
if(projectFolder){ if (projectFolder) {
ansibleEngine = angular.copy(Projects.selectedProject.ansibleEngine); ansibleEngine = angular.copy(Projects.selectedProject.ansibleEngine);
ansibleEngine.projectFolder = projectFolder ansibleEngine.projectFolder = projectFolder
} }
$http.post(uri + 'inventory/list',{ansibleEngine:ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'inventory/list', {ansibleEngine: ansibleEngine}).then(successCallback, errorCallback)
}; };
this.readInventory = function(inventoryName,successCallback,errorCallback){ this.readInventory = function (inventoryName, successCallback, errorCallback) {
$http.post(uri + 'inventory/get',{inventoryName:inventoryName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback) $http.post(uri + 'inventory/get', {
inventoryName: inventoryName,
ansibleEngine: Projects.selectedProject.ansibleEngine
}).then(successCallback, errorCallback)
}; };
this.deleteInventory = function(inventoryName,successCallback,errorCallback){ this.deleteInventory = function (inventoryName, successCallback, errorCallback) {
$http.post(uri + 'inventory/delete',{ansibleEngine:Projects.selectedProject.ansibleEngine,inventoryName:inventoryName}).then(successCallback,errorCallback) $http.post(uri + 'inventory/delete', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
inventoryName: inventoryName
}).then(successCallback, errorCallback)
}; };
this.createInventory = function(inventoryName,inventoryFileContents,successCallback,errorCallback){ this.createInventory = function (inventoryName, inventoryFileContents, successCallback, errorCallback) {
$http.post(uri + 'inventory/create',{ansibleEngine:Projects.selectedProject.ansibleEngine,inventoryName:inventoryName,inventoryFileContents:inventoryFileContents}).then(successCallback,errorCallback) $http.post(uri + 'inventory/create', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
inventoryName: inventoryName,
inventoryFileContents: inventoryFileContents
}).then(successCallback, errorCallback)
}; };
// -------------------------- Variable Files ------------------------- // -------------------------- Variable Files -------------------------
this.getVars = function(inventoryFileName, hostName, successCallback,errorCallback){ this.getVars = function (inventoryFileName, hostName, successCallback, errorCallback) {
$http.post(uri + 'vars/hosts/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,hostName:hostName,inventoryFileName:inventoryFileName}).then(successCallback,errorCallback) $http.post(uri + 'vars/hosts/get', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
hostName: hostName,
inventoryFileName: inventoryFileName
}).then(successCallback, errorCallback)
}; };
this.getRoleVars = function(roleName, successCallback,errorCallback){ this.getRoleVars = function (roleName, successCallback, errorCallback) {
$http.post(uri + 'vars/roles/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,roleName:roleName}).then(successCallback,errorCallback) $http.post(uri + 'vars/roles/get', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
roleName: roleName
}).then(successCallback, errorCallback)
}; };
this.updateGroupVarsFile = function(groupName,groupVarsContents,successCallback,errorCallback){ this.updateGroupVarsFile = function (groupName, groupVarsContents, successCallback, errorCallback) {
$http.post(uri + 'vars_file/groups/update',{ansibleEngine:Projects.selectedProject.ansibleEngine,groupName:groupName,groupVarsContents:groupVarsContents}).then(successCallback,errorCallback) $http.post(uri + 'vars_file/groups/update', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
groupName: groupName,
groupVarsContents: groupVarsContents
}).then(successCallback, errorCallback)
}; };
this.getGroupVarsFile = function(groupName,successCallback,errorCallback){ this.getGroupVarsFile = function (groupName, successCallback, errorCallback) {
$http.post(uri + 'vars_file/groups/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,groupName:groupName}).then(successCallback,errorCallback) $http.post(uri + 'vars_file/groups/get', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
groupName: groupName
}).then(successCallback, errorCallback)
}; };
this.updateHostVarsFile = function(hostName,hostVarsContents,successCallback,errorCallback){ this.updateHostVarsFile = function (hostName, hostVarsContents, successCallback, errorCallback) {
$http.post(uri + 'vars_file/hosts/update',{ansibleEngine:Projects.selectedProject.ansibleEngine,hostName:hostName,hostVarsContents:hostVarsContents}).then(successCallback,errorCallback) $http.post(uri + 'vars_file/hosts/update', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
hostName: hostName,
hostVarsContents: hostVarsContents
}).then(successCallback, errorCallback)
}; };
this.getHostVarsFile = function(hostName,successCallback,errorCallback){ this.getHostVarsFile = function (hostName, successCallback, errorCallback) {
$http.post(uri + 'vars_file/hosts/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,hostName:hostName}).then(successCallback,errorCallback) $http.post(uri + 'vars_file/hosts/get', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
hostName: hostName
}).then(successCallback, errorCallback)
}; };
// ------------------- TAGS LIST -------------------------- // ------------------- TAGS LIST --------------------------
this.getTagList = function(selectedPlaybook,inventory_file_name,ansibleEngine,successCallback,errorCallback){ this.getTagList = function (selectedPlaybook, inventory_file_name, ansibleEngine, successCallback, errorCallback) {
$http.post(uri + 'tags/list',{ansibleEngine:ansibleEngine,inventory_file_name:inventory_file_name,selectedPlaybook:selectedPlaybook}).then(successCallback,errorCallback) $http.post(uri + 'tags/list', {
ansibleEngine: ansibleEngine,
inventory_file_name: inventory_file_name,
selectedPlaybook: selectedPlaybook
}).then(successCallback, errorCallback)
}; };
// ------------- SOME HELPER FUNCTIONS -------------- // ------------- SOME HELPER FUNCTIONS --------------
this.parseINIString = function(data){ this.parseINIString = function (data) {
var regex = { var regex = {
section: /^\s*\[\s*([^\]]*)\s*\]\s*$/, section: /^\s*\[\s*([^\]]*)\s*\]\s*$/,
param: /^\s*([\w\.\-\_]+).*$/, param: /^\s*([\w\.\-\_]+).*$/,
@ -241,36 +379,36 @@ export function ansibleService($http,YAML,Projects) {
var lines = data.split(/\r\n|\r|\n/); var lines = data.split(/\r\n|\r|\n/);
var group = null; var group = null;
group = {'name':'Un grouped', 'members': [], 'type': 'default'}; group = {'name': 'Un grouped', 'members': [], 'type': 'default'};
groups.push(group); groups.push(group);
// groups.push({'name':'All Hosts', 'members': hosts, 'type': 'default'}); // groups.push({'name':'All Hosts', 'members': hosts, 'type': 'default'});
lines.forEach(function(line){ lines.forEach(function (line) {
if(regex.comment.test(line)){ if (regex.comment.test(line)) {
return; return;
}else if(regex.param.test(line)){ } else if (regex.param.test(line)) {
var match = line.match(regex.param); var match = line.match(regex.param);
var host = match[1]; var host = match[1];
if(hosts.indexOf(host) < 0){ if (hosts.indexOf(host) < 0) {
hosts.push(host); hosts.push(host);
} }
if(group && group.members.indexOf(host) < 0){ if (group && group.members.indexOf(host) < 0) {
group.members.push(host); group.members.push(host);
} }
}else if(regex.section.test(line)){ } else if (regex.section.test(line)) {
var match = line.match(regex.section); var match = line.match(regex.section);
group = {'name':match[1], 'members': [], 'type': 'userdefined'}; group = {'name': match[1], 'members': [], 'type': 'userdefined'};
groups.push(group); groups.push(group);
} }
}); });
return {'hosts':hosts,'groups':groups}; return {'hosts': hosts, 'groups': groups};
}; };
this.jsonToAnsibleInventoryIni = function(inventoryData){ this.jsonToAnsibleInventoryIni = function (inventoryData) {
var name = inventoryData.name; var name = inventoryData.name;
var hosts = inventoryData.hosts; var hosts = inventoryData.hosts;
@ -278,15 +416,15 @@ export function ansibleService($http,YAML,Projects) {
var result_lines = ['# Inventory File - ' + name, '']; var result_lines = ['# Inventory File - ' + name, ''];
angular.forEach(groups,function(group){ angular.forEach(groups, function (group) {
if(group.name == 'All Hosts')return; if (group.name == 'All Hosts')return;
if(group.name !== 'Un grouped'){ if (group.name !== 'Un grouped') {
result_lines.push(''); result_lines.push('');
result_lines.push('[' + group.name + ']'); result_lines.push('[' + group.name + ']');
} }
angular.forEach(group.members,function(member){ angular.forEach(group.members, function (member) {
result_lines.push(member); result_lines.push(member);
}) })

View file

@ -85,7 +85,7 @@ def play_vars():
def role_vars(): def role_vars():
parser.add_argument('--playbook_path', help='Test Playbook path for role - usually role/tests/test.yml', required=True) parser.add_argument('--playbook_path', help='Test Playbook path for role - usually role/tests/test.yml', required=True)
parser.add_argument('--vault_password_file', help='Vault password file - usually role/tests/test.yml', required=True) parser.add_argument('--vault_password_file', help='Vault password file - usually role/tests/test.yml')
args = parser.parse_args() args = parser.parse_args()
variable_manager = VariableManager() variable_manager = VariableManager()

View file

@ -9,9 +9,11 @@
"angular-aria": "~1.6.0", "angular-aria": "~1.6.0",
"angular-confirm": "^1.2.6", "angular-confirm": "^1.2.6",
"angular-cookies": "~1.6.0", "angular-cookies": "~1.6.0",
"angular-loading-bar": "^0.9.0",
"angular-markdown-directive": "^0.3.1", "angular-markdown-directive": "^0.3.1",
"angular-resource": "~1.6.0", "angular-resource": "~1.6.0",
"angular-sanitize": "^1.6.4", "angular-sanitize": "^1.6.4",
"angular-simple-sidebar": "^1.3.1",
"angular-tree-control": "^0.2.28", "angular-tree-control": "^0.2.28",
"angular-ui-ace": "^0.2.3", "angular-ui-ace": "^0.2.3",
"angular-ui-bootstrap": "^2.0.1", "angular-ui-bootstrap": "^2.0.1",
@ -44,6 +46,7 @@
"method-override": "^2.3.5", "method-override": "^2.3.5",
"mongoose": "^4.1.2", "mongoose": "^4.1.2",
"morgan": "^1.8.0", "morgan": "^1.8.0",
"ng-tags-input": "^3.2.0",
"passport": "~0.3.0", "passport": "~0.3.0",
"passport-facebook": "^2.0.0", "passport-facebook": "^2.0.0",
"passport-google-oauth20": "^1.0.0", "passport-google-oauth20": "^1.0.0",

View file

@ -574,7 +574,7 @@ exports.getRoleFiles = function(roleName, successCallback, errorCallback, ansibl
scp2_exec.copyFileToScriptEngine('./helpers/dir_tree.py','/tmp/dir_tree.py',ansibleEngine,function(){ scp2_exec.copyFileToScriptEngine('./helpers/dir_tree.py','/tmp/dir_tree.py',ansibleEngine,function(){
ssh2_exec.executeCommand(command,null,successCallback,errorCallback,ansibleEngine); ssh2_exec.executeCommand(command,null,successCallback,errorCallback,ansibleEngine);
}. errorCallback); }, errorCallback);
}; };