From babc1c5e6c8749267389cf201109e2c887c32804 Mon Sep 17 00:00:00 2001 From: Mumshad Mannambeth Date: Tue, 11 Jul 2017 13:11:17 -0400 Subject: [PATCH] Implement disabling playbook execution based on environment variable --- server/api/ansible/ansible.controller.js | 8 +++++++- server/api/custom_module/custom_module.controller.js | 9 +++++++-- server/components/ansible/ansible_tool.js | 10 +++++----- server/config/environment/shared.js | 5 ++++- server/config/local.env.sample.js | 10 +++++++++- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/server/api/ansible/ansible.controller.js b/server/api/ansible/ansible.controller.js index 1cdc2d6..66b1f7b 100644 --- a/server/api/ansible/ansible.controller.js +++ b/server/api/ansible/ansible.controller.js @@ -12,6 +12,7 @@ import jsonpatch from 'fast-json-patch'; import Ansible from './ansible.model'; +import config from '../../config/environment'; var ssh2_exec = require('../../components/ssh/ssh2_exec'); var ansibleTool = require('../../components/ansible/ansible_tool'); @@ -112,7 +113,6 @@ export function modules(req, res) { // Gets a single Deploy from the DB export function getLogs(req, res) { - console.log("Param ID " + req.params.id); return Ansible.findById(req.params.id).exec() .then(handleEntityNotFound(res)) .then(function(entity){ @@ -130,12 +130,18 @@ export function getLogs(req, res) { .catch(handleError(res)); } +console.log("config.disablePlayboookExecution =" + config.disablePlayboookExecution); + // Executes Ansible Play book in the backend export function execute(req, res) { //var inventory_file_contents = req.body.inventory_file_contents; //var playbook_file_contents = req.body.playbook_file_contents; + if(config.disablePlayboookExecution){ + return res.status(500).send('Playbook execution has been disabled. Set environment variable DISABLE_PLAYBOOK_EXECUTION to "false" and restart web server') + } + var playbook_name = req.body.selectedPlaybook; var inventory_file_name = req.body.inventory_file_name; diff --git a/server/api/custom_module/custom_module.controller.js b/server/api/custom_module/custom_module.controller.js index 92d497d..b81fd1d 100644 --- a/server/api/custom_module/custom_module.controller.js +++ b/server/api/custom_module/custom_module.controller.js @@ -12,8 +12,9 @@ import jsonpatch from 'fast-json-patch'; import CustomModule from './custom_module.model'; -var ssh2_exec = require('../../components/ssh/ssh2_exec'); -var scp2_exec = require('../../components/scp/scp_exec'); +import config from '../../config/environment'; +const ssh2_exec = require('../../components/ssh/ssh2_exec'); +const scp2_exec = require('../../components/scp/scp_exec'); const logger = require('../../components/logger/logger'); @@ -134,6 +135,10 @@ export function testModule(req, res) { var moduleArgs = req.body.moduleArgs; + if(config.disablePlayboookExecution){ + return res.status(500).send('Testing has been disabled. Set environment variable DISABLE_PLAYBOOK_EXECUTION to "false" and restart web server') + } + if(!ansibleEngine.customModules){ res.status(500).send("Custom Modules Folder not defined in Ansible Engine") } diff --git a/server/components/ansible/ansible_tool.js b/server/components/ansible/ansible_tool.js index bb289bc..055ba31 100644 --- a/server/components/ansible/ansible_tool.js +++ b/server/components/ansible/ansible_tool.js @@ -1,6 +1,6 @@ -var ssh2_exec = require('../ssh/ssh2_exec'); -var scp2_exec = require('../scp/scp_exec'); -var config = require('../../config/environment'); +const ssh2_exec = require('../ssh/ssh2_exec'); +const scp2_exec = require('../scp/scp_exec'); +const config = require('../../config/environment'); const util = require('util'); const Q = require("q"); @@ -8,7 +8,7 @@ const all_commands = require('../../config/commands'); const logger = require('../logger/logger'); -var local_logPath = 'logs/ansible/execute/'; +const local_logPath = 'logs/ansible/execute/'; /** * Get Logs @@ -373,7 +373,7 @@ exports.deletePlaybook = function(project_folder,playbook_file_name, dataCallbac exports.getPlaybookList = function(project_folder, successCallback, errorCallback, ansibleEngine){ var playbook_file_path = project_folder + '/'; - var command = util.format(all_commands.general.get_playbook_list, playbook_file_path); + var command = util.format(all_commands.ansible.get_playbook_list, playbook_file_path); var ansiblePlaybookListResults = ""; ssh2_exec.executeCommand(command, diff --git a/server/config/environment/shared.js b/server/config/environment/shared.js index 58c041a..69720d0 100644 --- a/server/config/environment/shared.js +++ b/server/config/environment/shared.js @@ -25,5 +25,8 @@ exports = module.exports = { ansible_project_library: '/library', // relative to project folder ansible_project_roles: '/roles', // relative to project folder - } + }, + + disablePlayboookExecution: process.env.DISABLE_PLAYBOOK_EXECUTION || false + }; diff --git a/server/config/local.env.sample.js b/server/config/local.env.sample.js index c929c39..e6e7e20 100644 --- a/server/config/local.env.sample.js +++ b/server/config/local.env.sample.js @@ -16,5 +16,13 @@ module.exports = { GOOGLE_SECRET: 'secret', // Control debug level for modules using visionmedia/debug - DEBUG: '' + DEBUG: '', + + SCRIPT_ENGINE_HOST : 'localhost', + SCRIPT_ENGINE_USER : 'root', + SCRIPT_ENGINE_PASSWORD : 'P@ssw0rd@123', + + MONGODB_URI_DEV: 'mongodb://localhost/dev', + + DISABLE_PLAYBOOK_EXECUTION: true };