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');
|
||||
|
||||
var config = require('../../config/environment');
|
||||
const config = require('../../config/environment');
|
||||
const logger = require('../logger/logger');
|
||||
|
||||
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();
|
||||
|
||||
if(!ansibleEngine) ansibleEngine = {};
|
||||
|
@ -32,22 +26,17 @@ exports.executeCommand = function(command, dataCallback,completeCallback,errorCa
|
|||
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) {
|
||||
cb([connHostPassword]);
|
||||
});
|
||||
|
||||
conn.on('error', function(error) {
|
||||
console.log("SSH Connect Error" + error);
|
||||
errorCallback(error);
|
||||
logger.error("SSH Connect Error" + error);
|
||||
errorCallback("SSH Connect Error" + error);
|
||||
});
|
||||
|
||||
conn.on('ready', function() {
|
||||
console.log('Client :: ready');
|
||||
console.log('Command :: ' + command);
|
||||
logger.info('Client :: ready');
|
||||
conn.exec(command, function(err, stream) {
|
||||
var callBackSent = false;
|
||||
|
||||
|
@ -56,15 +45,12 @@ exports.executeCommand = function(command, dataCallback,completeCallback,errorCa
|
|||
var error = false;
|
||||
|
||||
if (err) {
|
||||
console.log("Error=" + err);
|
||||
errorCallback(err);
|
||||
|
||||
logger.error("Error=" + err);
|
||||
errorCallback("Error=" + err);
|
||||
}
|
||||
stream.on('close', function(code, signal) {
|
||||
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
|
||||
//completeCallback('Stream :: close :: code: ' + code + ', signal: ' + signal + '\nSCRIPT_FINISHED');
|
||||
logger.info('Stream :: close :: code: ' + code + ', signal: ' + signal);
|
||||
if(addScriptEndString){
|
||||
//dataCallback call is what writes to logfile
|
||||
result_data += '\nSCRIPT_FINISHED';
|
||||
dataCallback(result_data);
|
||||
}
|
||||
|
@ -76,33 +62,19 @@ exports.executeCommand = function(command, dataCallback,completeCallback,errorCa
|
|||
}
|
||||
conn.end();
|
||||
}).on('data', function(data) {
|
||||
console.log('STDOUT: ' + data);
|
||||
logger.info('STDOUT: ' + data);
|
||||
result_data += data;
|
||||
if(dataCallback){
|
||||
//dataCallback(data);
|
||||
dataCallback(result_data);
|
||||
}
|
||||
|
||||
}).stderr.on('data', function(data) {
|
||||
console.log('STDERR: ' + data);
|
||||
logger.error('STDERR: ' + data);
|
||||
error_data += data;
|
||||
error = true;
|
||||
//errorCallback(data);
|
||||
|
||||
});
|
||||
});
|
||||
}).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