mirror of
https://github.com/mmumshad/ansible-playable.git
synced 2025-03-09 23:38:54 +00:00
Initial Commit
This commit is contained in:
commit
c92f737237
273 changed files with 16964 additions and 0 deletions
123
server/components/scp/scp_exec.js
Normal file
123
server/components/scp/scp_exec.js
Normal file
|
@ -0,0 +1,123 @@
|
|||
import config from '../../config/environment';
|
||||
//var config = require('../../config/environment/development.js');
|
||||
var client = require('scp2');
|
||||
|
||||
|
||||
exports.copyFileToScriptEngine = function(sourcePath,destinationPath,ansibleEngine){
|
||||
|
||||
var connHost = ansibleEngine.ansibleHost || config.scriptEngine.host;
|
||||
var connUser = ansibleEngine.ansibleHostUser || config.scriptEngine.user;
|
||||
var connHostPassword = ansibleEngine.ansibleHostPassword || config.scriptEngine.password;
|
||||
|
||||
var scriptEngineConfig = {
|
||||
host: connHost,
|
||||
port: 22,
|
||||
username: connUser,
|
||||
tryKeyboard: true
|
||||
};
|
||||
|
||||
if(connHostPassword){
|
||||
scriptEngineConfig.password = connHostPassword;
|
||||
}else{
|
||||
scriptEngineConfig.privateKey = require('fs').readFileSync(config.scriptEngine.privateKey);
|
||||
}
|
||||
|
||||
scriptEngineConfig.destinationPath = destinationPath;
|
||||
var Client = require('scp2').Client;
|
||||
var cl = new Client(scriptEngineConfig);
|
||||
|
||||
cl.on('keyboard-interactive', function(name, instr, lang, prompts, cb) {
|
||||
cb([connHostPassword]);
|
||||
});
|
||||
|
||||
cl.on('error', function(error) {
|
||||
console.log("SCP Connect Error" + error);
|
||||
return error
|
||||
});
|
||||
|
||||
cl.upload(sourcePath,destinationPath,function(err) {
|
||||
if(err){
|
||||
console.error(err)
|
||||
}else{
|
||||
console.log("Successfully uploaded file")
|
||||
cl.close()
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
exports.createFileOnScriptEngine = function(contents,destinationPath,successCallback,errorCallback,ansibleEngine){
|
||||
var Client = require('scp2').Client;
|
||||
var buffer = new Buffer(contents, "utf-8");
|
||||
|
||||
if(!ansibleEngine) ansibleEngine = {};
|
||||
|
||||
var connHost = ansibleEngine.ansibleHost || config.scriptEngine.host;
|
||||
var connUser = ansibleEngine.ansibleHostUser || config.scriptEngine.user;
|
||||
var connHostPassword = ansibleEngine.ansibleHostPassword || config.scriptEngine.password;
|
||||
|
||||
var scriptEngineConfig = {
|
||||
host: connHost,
|
||||
port: 22,
|
||||
username: connUser,
|
||||
tryKeyboard: true
|
||||
};
|
||||
|
||||
if(connHostPassword){
|
||||
scriptEngineConfig.password = connHostPassword;
|
||||
}else{
|
||||
scriptEngineConfig.privateKey = require('fs').readFileSync(config.scriptEngine.privateKey);
|
||||
}
|
||||
|
||||
|
||||
var cl = new Client(scriptEngineConfig);
|
||||
|
||||
cl.on('keyboard-interactive', function(name, instr, lang, prompts, cb) {
|
||||
cb([connHostPassword]);
|
||||
});
|
||||
|
||||
cl.on('error', function(error) {
|
||||
console.log("SCP Connect Error" + error);
|
||||
errorCallback(error);
|
||||
});
|
||||
|
||||
//cl.connect(scriptEngineConfig);
|
||||
|
||||
var dirname = destinationPath.match(/(.*)[\/\\]/)[1]||'';
|
||||
|
||||
console.log("direcname = " + dirname);
|
||||
|
||||
cl.mkdir(dirname,function(err){
|
||||
if(err){
|
||||
errorCallback('Failed to create directory - ' + dirname + ' -' + err)
|
||||
return cl.close()
|
||||
}
|
||||
|
||||
cl.write({
|
||||
destination: destinationPath,
|
||||
content: buffer
|
||||
}, function(err){
|
||||
if(err){
|
||||
console.error(err);
|
||||
errorCallback(err);
|
||||
|
||||
}else{
|
||||
console.log("Success ");
|
||||
successCallback()
|
||||
}
|
||||
cl.close()
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
//exports.copyFileToScriptEngine('scp_exec.js','/tmp/ssh_tezt.js');
|
||||
/*
|
||||
exports.createFileOnScriptEngine('sdfdddddddddsfd','/tmp/testfile.txt', function(response){
|
||||
console.log("Success" + response)
|
||||
}, function(response){
|
||||
console.log("Error" + response)
|
||||
});
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue