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:
parent
a71d1109a8
commit
02ab635fe7
10 changed files with 361 additions and 194 deletions
|
@ -20,11 +20,17 @@ import 'ansi-to-html';
|
|||
|
||||
import 'angular-markdown-directive';
|
||||
|
||||
import 'ng-tags-input';
|
||||
|
||||
import 'angular-loading-bar';
|
||||
|
||||
import treecontrol from 'angular-tree-control';
|
||||
|
||||
import 'angular-tree-control/css/tree-control-attribute.css';
|
||||
import 'angular-tree-control/css/tree-control.css';
|
||||
|
||||
import 'ng-tags-input/build/ng-tags-input.min.css';
|
||||
|
||||
import {
|
||||
routeConfig
|
||||
} from './app.config';
|
||||
|
@ -102,7 +108,7 @@ angular.module('app2App', [ngCookies, ngResource, ngSanitize, uiRouter, uiBootst
|
|||
// Filters
|
||||
dictToKeyValueArray, dictToKeyValueArraySimple, keyValueArrayToDict, keyValueArrayToArray, addDotInKey, removeDotInKey, json2yaml,
|
||||
// Directives
|
||||
complexVar, tasks, treecontrol, 'btford.markdown'
|
||||
complexVar, tasks, treecontrol, 'btford.markdown', 'ngTagsInput', 'angular-loading-bar'
|
||||
|
||||
])
|
||||
.config(routeConfig)
|
||||
|
|
|
@ -35,6 +35,8 @@ export class DesignerComponent {
|
|||
Projects.selectedProject = $scope.selectedProject;
|
||||
$scope.listOfInventoryFiles();
|
||||
$scope.$broadcast('projectLoaded');
|
||||
// Refresh modules list on project load
|
||||
ansible.getAnsibleModules();
|
||||
})
|
||||
|
||||
};
|
||||
|
|
|
@ -1,47 +1,56 @@
|
|||
<div style="padding:15px;">
|
||||
<div class="row">
|
||||
<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-heading">Projects</div>
|
||||
<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 class="panel">
|
||||
-->
|
||||
<!--<div class="panel">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Inventory Files</div>
|
||||
<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 class="panel">
|
||||
<!--<div class="panel">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Menu</div>
|
||||
<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 class="alert alert-danger" ng-if="err_msg">{{err_msg}}</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -55,8 +55,9 @@ export function newTaskController($window, $scope, $sce, $uibModal, ansi2html, a
|
|||
selectedTask = angular.copy(selectedTask);
|
||||
$scope.newTask = selectedTask;
|
||||
if(selectedTask.tags)$scope.newTask.tags = $scope.newTask.tags.join(',');
|
||||
var module = $scope.getModuleFromTask(selectedTask);
|
||||
$scope.getModuleDescription(module,true)
|
||||
$scope.getModuleFromTask(selectedTask, module => {
|
||||
$scope.getModuleDescription(module,true)
|
||||
});
|
||||
}
|
||||
|
||||
}, function(response){
|
||||
|
@ -180,66 +181,68 @@ export function newTaskController($window, $scope, $sce, $uibModal, ansi2html, a
|
|||
* @param task - Single task object containing task properties
|
||||
* @returns {{}}
|
||||
*/
|
||||
$scope.getModuleFromTask = function(task){
|
||||
$scope.getModuleFromTask = function(task, successCallback){
|
||||
var moduleObject = {};
|
||||
$scope.local_action = false;
|
||||
var task_properties = null;
|
||||
|
||||
var module = ansible.getModuleFromTask(task);
|
||||
|
||||
if(module === 'include'){
|
||||
module = null;
|
||||
task.tags = task.include.replace(/.*tags=(.*)/,"$1")
|
||||
return;
|
||||
}else if(module === 'local_action'){
|
||||
$scope.local_action = true;
|
||||
module = task.local_action.module;
|
||||
task_properties = task.local_action;
|
||||
delete task_properties.module;
|
||||
}else{
|
||||
task_properties = task[module];
|
||||
}
|
||||
|
||||
angular.forEach($scope.modules, function(item,index) {
|
||||
if(item.name == module){
|
||||
moduleObject = item;
|
||||
$scope.newTask.module = item;
|
||||
ansible.getModuleFromTask(task, module => {
|
||||
if(module === 'include'){
|
||||
module = null;
|
||||
task.tags = task.include.replace(/.*tags=(.*)/,"$1")
|
||||
return;
|
||||
}else if(module === 'local_action'){
|
||||
$scope.local_action = true;
|
||||
module = task.local_action.module;
|
||||
task_properties = task.local_action;
|
||||
delete task_properties.module;
|
||||
}else{
|
||||
task_properties = task[module];
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -27,14 +27,15 @@ export default angular.module('webAppApp.tasks', [])
|
|||
scope.tasksMetaData = [];
|
||||
|
||||
angular.forEach(scope.tasksList,function(task){
|
||||
var taskModule = ansible.getModuleFromTask(task);
|
||||
var taskName = task.name;
|
||||
ansible.getModuleFromTask(task, taskModule => {
|
||||
var taskName = task.name;
|
||||
|
||||
if(taskModule === 'include'){
|
||||
taskName = task[taskModule].replace(/(.*yml) .*/,"$1")
|
||||
}
|
||||
if(taskModule === 'include'){
|
||||
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);
|
||||
|
|
|
@ -13,7 +13,12 @@
|
|||
<td><input type="checkbox" ng-model="tasksMetaData[$index].selected">
|
||||
</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>
|
||||
<div class="btn-group">
|
||||
<label class="btn btn-default btn-sm" ng-click="showTaskModal($index)"><span
|
||||
|
|
|
@ -2,234 +2,372 @@
|
|||
const angular = require('angular');
|
||||
|
||||
/*@ngInject*/
|
||||
export function ansibleService($http,YAML,Projects) {
|
||||
// AngularJS will instantiate a singleton by calling "new" on this function
|
||||
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
|
||||
|
||||
var AnsibleService = this;
|
||||
|
||||
var uri = '/api/ansible/';
|
||||
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 = {};
|
||||
|
||||
this.getAnsibleModules = function(successCallback,errorCallback,parent,refresh){
|
||||
if(!refresh && AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost])
|
||||
// A cache map of hosts and modules names.
|
||||
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]);
|
||||
|
||||
try{
|
||||
if(!refresh && JSON.parse(localStorage['modules_' + Projects.selectedProject.ansibleEngine.ansibleHost]))
|
||||
try {
|
||||
if (!refresh && 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)
|
||||
}
|
||||
|
||||
$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');
|
||||
AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost] = result.map(function(item){
|
||||
return {"name" : item.split(" ")[0], "description": item.split(/ (.+)?/)[1]}
|
||||
AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost] = result.map(function (item) {
|
||||
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{
|
||||
if(!refresh && JSON.parse(localStorage['module_description_' + Projects.selectedProject.ansibleEngine.ansibleHost + '_' + moduleName]))
|
||||
try {
|
||||
if (!refresh && 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;
|
||||
|
||||
if(Projects.selectedProject.ansibleEngine.customModules){
|
||||
if (Projects.selectedProject.ansibleEngine.customModules) {
|
||||
command = 'export ANSIBLE_LIBRARY="' + Projects.selectedProject.ansibleEngine.customModules + '"; ' + command;
|
||||
}
|
||||
|
||||
$http.post(uri + 'command',{ansibleEngine:Projects.selectedProject.ansibleEngine,command:command})
|
||||
.then(function(response){
|
||||
$http.post(uri + 'command', {ansibleEngine: Projects.selectedProject.ansibleEngine, command: command})
|
||||
.then(function (response) {
|
||||
|
||||
localStorage['module_description_' + Projects.selectedProject.ansibleEngine.ansibleHost + '_' + moduleName] = JSON.stringify(response.data);
|
||||
successCallback(response.data)
|
||||
|
||||
},errorCallback)
|
||||
}, errorCallback)
|
||||
|
||||
};
|
||||
|
||||
this.executeAnsiblePlayBook = function(body,successCallback,errorCallback,parent){
|
||||
$http.post(uri + 'execute',body).then(successCallback,errorCallback)
|
||||
this.executeAnsiblePlayBook = function (body, successCallback, errorCallback, parent) {
|
||||
$http.post(uri + 'execute', body).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
this.executeCommand = function(command, successCallback,errorCallback){
|
||||
$http.post(uri + 'command',{command:command,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.executeCommand = function (command, successCallback, errorCallback) {
|
||||
$http.post(uri + 'command', {
|
||||
command: command,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
this.getLogs = function(executionData,successCallback,errorCallback){
|
||||
$http.get(uri+'logs/'+executionData._id).then(successCallback,errorCallback);
|
||||
this.getLogs = function (executionData, successCallback, errorCallback) {
|
||||
$http.get(uri + 'logs/' + executionData._id).then(successCallback, errorCallback);
|
||||
};
|
||||
|
||||
this.query = function(successCallback,errorCallback){
|
||||
$http.get(uri).then(successCallback,errorCallback);
|
||||
this.query = function (successCallback, errorCallback) {
|
||||
$http.get(uri).then(successCallback, errorCallback);
|
||||
};
|
||||
|
||||
this.getModuleFromTask = function(task){
|
||||
this.getModuleFromTask = function (task, successCallback, errorCallback) {
|
||||
var module = null;
|
||||
angular.forEach(JSON.parse(angular.toJson(task)), function(value, key) {
|
||||
if(defaultTaskProperties.indexOf(key) < 0){
|
||||
module = key
|
||||
console.log("Getting module from task");
|
||||
|
||||
|
||||
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){
|
||||
task.tags = task.include.replace(/.*tags=(.*)/,"$1")
|
||||
}
|
||||
successCallback(module);
|
||||
|
||||
}, errorCallback);
|
||||
|
||||
return module;
|
||||
|
||||
};
|
||||
// -------------------------- PROJECT -------------------------
|
||||
this.getProjectFiles = function(successCallback,errorCallback){
|
||||
$http.post(uri + 'project/files',{ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.getProjectFiles = function (successCallback, errorCallback) {
|
||||
$http.post(uri + 'project/files', {ansibleEngine: Projects.selectedProject.ansibleEngine}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
|
||||
// -------------------------- PLAYBOOK -------------------------
|
||||
|
||||
this.getPlaybookList = function(successCallback,errorCallback){
|
||||
$http.post(uri + 'playbook/list',{ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.getPlaybookList = function (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);
|
||||
$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){
|
||||
$http.post(uri + 'playbook/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,playbookName:playbookName}).then(successCallback,errorCallback)
|
||||
this.readPlaybook = function (playbookName, 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)
|
||||
};
|
||||
|
||||
// -------------------------- ROLES -------------------------
|
||||
|
||||
this.getRoleList = function(successCallback,errorCallback){
|
||||
$http.post(uri + 'roles/list',{ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.getRoleList = function (successCallback, errorCallback) {
|
||||
$http.post(uri + 'roles/list', {ansibleEngine: Projects.selectedProject.ansibleEngine}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
this.searchRolesGalaxy = function(searchText,successCallback,errorCallback){
|
||||
$http.post(uri + 'roles/search/galaxy',{searchText:searchText,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.searchRolesGalaxy = function (searchText, successCallback, errorCallback) {
|
||||
$http.post(uri + 'roles/search/galaxy', {
|
||||
searchText: searchText,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
this.searchRolesGithub = function(searchText,successCallback,errorCallback){
|
||||
$http.post(uri + 'roles/search/github',{searchText:searchText,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.searchRolesGithub = function (searchText, successCallback, errorCallback) {
|
||||
$http.post(uri + 'roles/search/github', {
|
||||
searchText: searchText,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
this.createRole = function(roleName,successCallback,errorCallback,selectedRoleName){
|
||||
$http.post(uri + 'roles/create',{roleName:roleName,selectedRoleName:selectedRoleName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.createRole = function (roleName, successCallback, errorCallback, selectedRoleName) {
|
||||
$http.post(uri + 'roles/create', {
|
||||
roleName: roleName,
|
||||
selectedRoleName: selectedRoleName,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(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)
|
||||
this.importRole = function (roleType, roleNameUri, successCallback, errorCallback) {
|
||||
$http.post(uri + 'roles/import', {
|
||||
roleType: roleType,
|
||||
roleNameUri: roleNameUri,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
this.deleteRole = function(roleName,successCallback,errorCallback){
|
||||
$http.post(uri + 'roles/delete',{roleName:roleName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.deleteRole = function (roleName, successCallback, errorCallback) {
|
||||
$http.post(uri + 'roles/delete', {
|
||||
roleName: roleName,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
this.getRoleFiles = function(roleName,successCallback,errorCallback){
|
||||
$http.post(uri + 'roles/files',{roleName:roleName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.getRoleFiles = function (roleName, successCallback, errorCallback) {
|
||||
$http.post(uri + 'roles/files', {
|
||||
roleName: roleName,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
// -------------------------- FILES -------------------------
|
||||
|
||||
this.createFile = function(fileAbsolutePath,successCallback,errorCallback,selectedFileName){
|
||||
$http.post(uri + 'files/create',{fileAbsolutePath:fileAbsolutePath,selectedFileName:selectedFileName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.createFile = function (fileAbsolutePath, successCallback, errorCallback, selectedFileName) {
|
||||
$http.post(uri + 'files/create', {
|
||||
fileAbsolutePath: fileAbsolutePath,
|
||||
selectedFileName: selectedFileName,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
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)
|
||||
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)
|
||||
};
|
||||
|
||||
this.deleteFile = function(fileAbsolutePath,successCallback,errorCallback,selectedFileName){
|
||||
$http.post(uri + 'files/delete',{fileAbsolutePath:fileAbsolutePath,selectedFileName:selectedFileName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.deleteFile = function (fileAbsolutePath, successCallback, errorCallback, selectedFileName) {
|
||||
$http.post(uri + 'files/delete', {
|
||||
fileAbsolutePath: fileAbsolutePath,
|
||||
selectedFileName: selectedFileName,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
// -------------------------- INVENTORY -------------------------
|
||||
|
||||
this.getInventoryList = function(successCallback,errorCallback, projectFolder){
|
||||
this.getInventoryList = function (successCallback, errorCallback, projectFolder) {
|
||||
// Override project folder for other cases, such as roles
|
||||
var ansibleEngine = Projects.selectedProject.ansibleEngine;
|
||||
if(projectFolder){
|
||||
if (projectFolder) {
|
||||
ansibleEngine = angular.copy(Projects.selectedProject.ansibleEngine);
|
||||
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){
|
||||
$http.post(uri + 'inventory/get',{inventoryName:inventoryName,ansibleEngine:Projects.selectedProject.ansibleEngine}).then(successCallback,errorCallback)
|
||||
this.readInventory = function (inventoryName, successCallback, errorCallback) {
|
||||
$http.post(uri + 'inventory/get', {
|
||||
inventoryName: inventoryName,
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
this.deleteInventory = function(inventoryName,successCallback,errorCallback){
|
||||
$http.post(uri + 'inventory/delete',{ansibleEngine:Projects.selectedProject.ansibleEngine,inventoryName:inventoryName}).then(successCallback,errorCallback)
|
||||
this.deleteInventory = function (inventoryName, successCallback, errorCallback) {
|
||||
$http.post(uri + 'inventory/delete', {
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine,
|
||||
inventoryName: inventoryName
|
||||
}).then(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)
|
||||
this.createInventory = function (inventoryName, inventoryFileContents, successCallback, errorCallback) {
|
||||
$http.post(uri + 'inventory/create', {
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine,
|
||||
inventoryName: inventoryName,
|
||||
inventoryFileContents: inventoryFileContents
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
// -------------------------- Variable Files -------------------------
|
||||
|
||||
this.getVars = function(inventoryFileName, hostName, successCallback,errorCallback){
|
||||
$http.post(uri + 'vars/hosts/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,hostName:hostName,inventoryFileName:inventoryFileName}).then(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)
|
||||
};
|
||||
|
||||
this.getRoleVars = function(roleName, successCallback,errorCallback){
|
||||
$http.post(uri + 'vars/roles/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,roleName:roleName}).then(successCallback,errorCallback)
|
||||
this.getRoleVars = function (roleName, successCallback, errorCallback) {
|
||||
$http.post(uri + 'vars/roles/get', {
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine,
|
||||
roleName: roleName
|
||||
}).then(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)
|
||||
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)
|
||||
};
|
||||
|
||||
this.getGroupVarsFile = function(groupName,successCallback,errorCallback){
|
||||
$http.post(uri + 'vars_file/groups/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,groupName:groupName}).then(successCallback,errorCallback)
|
||||
this.getGroupVarsFile = function (groupName, 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){
|
||||
$http.post(uri + 'vars_file/hosts/update',{ansibleEngine:Projects.selectedProject.ansibleEngine,hostName:hostName,hostVarsContents:hostVarsContents}).then(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)
|
||||
};
|
||||
|
||||
this.getHostVarsFile = function(hostName,successCallback,errorCallback){
|
||||
$http.post(uri + 'vars_file/hosts/get',{ansibleEngine:Projects.selectedProject.ansibleEngine,hostName:hostName}).then(successCallback,errorCallback)
|
||||
this.getHostVarsFile = function (hostName, successCallback, errorCallback) {
|
||||
$http.post(uri + 'vars_file/hosts/get', {
|
||||
ansibleEngine: Projects.selectedProject.ansibleEngine,
|
||||
hostName: hostName
|
||||
}).then(successCallback, errorCallback)
|
||||
};
|
||||
|
||||
// ------------------- TAGS LIST --------------------------
|
||||
|
||||
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)
|
||||
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)
|
||||
};
|
||||
|
||||
// ------------- SOME HELPER FUNCTIONS --------------
|
||||
|
||||
this.parseINIString = function(data){
|
||||
this.parseINIString = function (data) {
|
||||
var regex = {
|
||||
section: /^\s*\[\s*([^\]]*)\s*\]\s*$/,
|
||||
param: /^\s*([\w\.\-\_]+).*$/,
|
||||
|
@ -241,36 +379,36 @@ export function ansibleService($http,YAML,Projects) {
|
|||
var lines = data.split(/\r\n|\r|\n/);
|
||||
var group = null;
|
||||
|
||||
group = {'name':'Un grouped', 'members': [], 'type': 'default'};
|
||||
group = {'name': 'Un grouped', 'members': [], 'type': 'default'};
|
||||
groups.push(group);
|
||||
|
||||
// groups.push({'name':'All Hosts', 'members': hosts, 'type': 'default'});
|
||||
|
||||
lines.forEach(function(line){
|
||||
if(regex.comment.test(line)){
|
||||
lines.forEach(function (line) {
|
||||
if (regex.comment.test(line)) {
|
||||
return;
|
||||
}else if(regex.param.test(line)){
|
||||
} else if (regex.param.test(line)) {
|
||||
var match = line.match(regex.param);
|
||||
var host = match[1];
|
||||
if(hosts.indexOf(host) < 0){
|
||||
if (hosts.indexOf(host) < 0) {
|
||||
hosts.push(host);
|
||||
}
|
||||
|
||||
if(group && group.members.indexOf(host) < 0){
|
||||
if (group && group.members.indexOf(host) < 0) {
|
||||
group.members.push(host);
|
||||
}
|
||||
|
||||
}else if(regex.section.test(line)){
|
||||
} else if (regex.section.test(line)) {
|
||||
var match = line.match(regex.section);
|
||||
group = {'name':match[1], 'members': [], 'type': 'userdefined'};
|
||||
group = {'name': match[1], 'members': [], 'type': 'userdefined'};
|
||||
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 hosts = inventoryData.hosts;
|
||||
|
@ -278,15 +416,15 @@ export function ansibleService($http,YAML,Projects) {
|
|||
|
||||
var result_lines = ['# Inventory File - ' + name, ''];
|
||||
|
||||
angular.forEach(groups,function(group){
|
||||
if(group.name == 'All Hosts')return;
|
||||
angular.forEach(groups, function (group) {
|
||||
if (group.name == 'All Hosts')return;
|
||||
|
||||
if(group.name !== 'Un grouped'){
|
||||
if (group.name !== 'Un grouped') {
|
||||
result_lines.push('');
|
||||
result_lines.push('[' + group.name + ']');
|
||||
}
|
||||
|
||||
angular.forEach(group.members,function(member){
|
||||
angular.forEach(group.members, function (member) {
|
||||
result_lines.push(member);
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue