mirror of
https://github.com/mmumshad/ansible-playable.git
synced 2025-03-09 23:38:54 +00:00
Improve logging and fix callback error
This commit is contained in:
parent
0bcc558413
commit
0be82d9deb
1 changed files with 11 additions and 39 deletions
|
@ -1,16 +1,10 @@
|
||||||
var Client = require('ssh2').Client;
|
const Client = require('ssh2').Client;
|
||||||
|
|
||||||
//var exec = require('ssh-exec');
|
const config = require('../../config/environment');
|
||||||
|
const logger = require('../logger/logger');
|
||||||
var config = require('../../config/environment');
|
|
||||||
|
|
||||||
exports.executeCommand = function(command, dataCallback,completeCallback,errorCallback, ansibleEngine, addScriptEndString){
|
exports.executeCommand = function(command, dataCallback,completeCallback,errorCallback, ansibleEngine, addScriptEndString){
|
||||||
|
|
||||||
/*var fs = require('filendir');
|
|
||||||
var time = new Date().getTime();
|
|
||||||
//var logFile = 'logs/deploy/' + logfilename;
|
|
||||||
var logFile = logfilelocation;*/
|
|
||||||
|
|
||||||
var conn = new Client();
|
var conn = new Client();
|
||||||
|
|
||||||
if(!ansibleEngine) ansibleEngine = {};
|
if(!ansibleEngine) ansibleEngine = {};
|
||||||
|
@ -32,22 +26,17 @@ exports.executeCommand = function(command, dataCallback,completeCallback,errorCa
|
||||||
scriptEngineConfig.privateKey = require('fs').readFileSync(config.scriptEngine.privateKey);
|
scriptEngineConfig.privateKey = require('fs').readFileSync(config.scriptEngine.privateKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
//fs.appendFile(logFile,command);
|
|
||||||
//console.log("Writing Command to log file =" + command)
|
|
||||||
/*fs.writeFile(logFile,"\n",{'flag':'a'});*/
|
|
||||||
|
|
||||||
conn.on('keyboard-interactive', function(name, instr, lang, prompts, cb) {
|
conn.on('keyboard-interactive', function(name, instr, lang, prompts, cb) {
|
||||||
cb([connHostPassword]);
|
cb([connHostPassword]);
|
||||||
});
|
});
|
||||||
|
|
||||||
conn.on('error', function(error) {
|
conn.on('error', function(error) {
|
||||||
console.log("SSH Connect Error" + error);
|
logger.error("SSH Connect Error" + error);
|
||||||
errorCallback(error);
|
errorCallback("SSH Connect Error" + error);
|
||||||
});
|
});
|
||||||
|
|
||||||
conn.on('ready', function() {
|
conn.on('ready', function() {
|
||||||
console.log('Client :: ready');
|
logger.info('Client :: ready');
|
||||||
console.log('Command :: ' + command);
|
|
||||||
conn.exec(command, function(err, stream) {
|
conn.exec(command, function(err, stream) {
|
||||||
var callBackSent = false;
|
var callBackSent = false;
|
||||||
|
|
||||||
|
@ -56,15 +45,12 @@ exports.executeCommand = function(command, dataCallback,completeCallback,errorCa
|
||||||
var error = false;
|
var error = false;
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("Error=" + err);
|
logger.error("Error=" + err);
|
||||||
errorCallback(err);
|
errorCallback("Error=" + err);
|
||||||
|
|
||||||
}
|
}
|
||||||
stream.on('close', function(code, signal) {
|
stream.on('close', function(code, signal) {
|
||||||
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
|
logger.info('Stream :: close :: code: ' + code + ', signal: ' + signal);
|
||||||
//completeCallback('Stream :: close :: code: ' + code + ', signal: ' + signal + '\nSCRIPT_FINISHED');
|
|
||||||
if(addScriptEndString){
|
if(addScriptEndString){
|
||||||
//dataCallback call is what writes to logfile
|
|
||||||
result_data += '\nSCRIPT_FINISHED';
|
result_data += '\nSCRIPT_FINISHED';
|
||||||
dataCallback(result_data);
|
dataCallback(result_data);
|
||||||
}
|
}
|
||||||
|
@ -76,33 +62,19 @@ exports.executeCommand = function(command, dataCallback,completeCallback,errorCa
|
||||||
}
|
}
|
||||||
conn.end();
|
conn.end();
|
||||||
}).on('data', function(data) {
|
}).on('data', function(data) {
|
||||||
console.log('STDOUT: ' + data);
|
logger.info('STDOUT: ' + data);
|
||||||
result_data += data;
|
result_data += data;
|
||||||
if(dataCallback){
|
if(dataCallback){
|
||||||
//dataCallback(data);
|
|
||||||
dataCallback(result_data);
|
dataCallback(result_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}).stderr.on('data', function(data) {
|
}).stderr.on('data', function(data) {
|
||||||
console.log('STDERR: ' + data);
|
logger.error('STDERR: ' + data);
|
||||||
error_data += data;
|
error_data += data;
|
||||||
error = true;
|
error = true;
|
||||||
//errorCallback(data);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).connect(scriptEngineConfig);
|
}).connect(scriptEngineConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//exports.executeCommand(null,'python3.4 /data/ehc-builder/scripts/vipr/python/ehc-builder/scripts/bin/main.py vro all --inputfile="configure_vmware_vro_Mumshad_Mannambeth_1468092975124.in" --logfile="configure_vmware_vro_Mumshad_Mannambeth_1468092975124"', 'logs/deploy/configure_vmware_vro_Mumshad_Mannambeth_1468092975124.log' )
|
|
||||||
/*
|
|
||||||
|
|
||||||
exports.executeCommand(null,'date','testfile.log',function(response){
|
|
||||||
console.log(response)
|
|
||||||
},function(response){
|
|
||||||
console.log(response)
|
|
||||||
},function(response){
|
|
||||||
console.log(response)
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue