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 '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)

View file

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

View file

@ -1,47 +1,56 @@
<div style="padding:15px;">
<div class="row">
<div class="col-md-2">
<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 panel-default">
<div class="panel-heading">Inventory Files</div>
<div class="panel-body">
<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>
</div>
</div>
</div>
<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="...">
<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">
</div>
</div>
</div>
-->
<!--<div class="panel">
<div class="panel panel-default">
<div class="panel-heading">Inventory Files</div>
<div class="panel-body">
</div>
</div>
</div>-->
<!--<div class="panel">
<div class="panel panel-default">
<div class="panel-heading">Menu</div>
<div class="panel-body">
</div>
</div>
</div>-->
<div class="alert alert-danger" ng-if="err_msg">{{err_msg}}</div>
</div>

View file

@ -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.getModuleFromTask(selectedTask, module => {
$scope.getModuleDescription(module,true)
});
}
}, function(response){
@ -180,13 +181,12 @@ 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);
ansible.getModuleFromTask(task, module => {
if(module === 'include'){
module = null;
task.tags = task.include.replace(/.*tags=(.*)/,"$1")
@ -239,7 +239,10 @@ export function newTaskController($window, $scope, $sce, $uibModal, ansi2html, a
},moduleObject.variables)
}
return moduleObject
successCallback(moduleObject);
});
};

View file

@ -27,7 +27,7 @@ export default angular.module('webAppApp.tasks', [])
scope.tasksMetaData = [];
angular.forEach(scope.tasksList,function(task){
var taskModule = ansible.getModuleFromTask(task);
ansible.getModuleFromTask(task, taskModule => {
var taskName = task.name;
if(taskModule === 'include'){
@ -35,6 +35,7 @@ export default angular.module('webAppApp.tasks', [])
}
scope.tasksMetaData.push({taskModule:taskModule,taskName:taskName,selected:false})
});
})
},true);

View file

@ -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

View file

@ -13,9 +13,35 @@ export function ansibleService($http,YAML,Projects) {
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 = {};
// 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]);
@ -26,17 +52,40 @@ export function ansibleService($http,YAML,Projects) {
//console.error(e)
}
// 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.module_names[Projects.selectedProject.ansibleEngine.ansibleHost] = AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost].map(module => {
return module.name;
});
localStorage['modules_' + Projects.selectedProject.ansibleEngine.ansibleHost] = JSON.stringify(AnsibleService.modules[Projects.selectedProject.ansibleEngine.ansibleHost]);
successCallback(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)
};
@ -70,7 +119,10 @@ export function ansibleService($http,YAML,Projects) {
};
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) {
@ -81,10 +133,15 @@ export function ansibleService($http,YAML,Projects) {
$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){
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
}
});
@ -93,7 +150,10 @@ export function ansibleService($http,YAML,Projects) {
task.tags = task.include.replace(/.*tags=(.*)/, "$1")
}
return module;
successCallback(module);
}, errorCallback);
};
// -------------------------- PROJECT -------------------------
@ -110,17 +170,27 @@ export function ansibleService($http,YAML,Projects) {
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) {
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)
$http.post(uri + 'playbook/get', {
ansibleEngine: Projects.selectedProject.ansibleEngine,
playbookName: playbookName
}).then(successCallback, errorCallback)
};
this.readPlaybookData = function (playbookData) {
@ -134,41 +204,74 @@ export function ansibleService($http,YAML,Projects) {
};
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) {
$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) {
$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) {
$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) {
$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) {
$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 -------------------------
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) {
$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) {
$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 -------------------------
@ -184,47 +287,82 @@ export function ansibleService($http,YAML,Projects) {
};
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) {
$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) {
$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 -------------------------
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) {
$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) {
$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) {
$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) {
$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) {
$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 --------------------------
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 --------------

View file

@ -85,7 +85,7 @@ def play_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('--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()
variable_manager = VariableManager()

View file

@ -9,9 +9,11 @@
"angular-aria": "~1.6.0",
"angular-confirm": "^1.2.6",
"angular-cookies": "~1.6.0",
"angular-loading-bar": "^0.9.0",
"angular-markdown-directive": "^0.3.1",
"angular-resource": "~1.6.0",
"angular-sanitize": "^1.6.4",
"angular-simple-sidebar": "^1.3.1",
"angular-tree-control": "^0.2.28",
"angular-ui-ace": "^0.2.3",
"angular-ui-bootstrap": "^2.0.1",
@ -44,6 +46,7 @@
"method-override": "^2.3.5",
"mongoose": "^4.1.2",
"morgan": "^1.8.0",
"ng-tags-input": "^3.2.0",
"passport": "~0.3.0",
"passport-facebook": "^2.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(){
ssh2_exec.executeCommand(command,null,successCallback,errorCallback,ansibleEngine);
}. errorCallback);
}, errorCallback);
};