Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ export class ansibleRemoteMachineInterface extends ansibleCommandLineInterface {
if (!ansibleUtils.testIfFileExist(path.join(playbookRoot,playbookFile))) {
throw tl.loc('PlaybookNotPresent', playbookFile, playbookRoot);
}
var playbookFullPath = playbookRoot + '/' + playbookFile;
var remotePlaybookRoot = '/tmp/' + path.basename(playbookFile);
var remotePlaybookRoot = '/tmp/' + path.basename(playbookRoot);
tl.debug('ansiblePlaybookRootPath = ' + '"' + remotePlaybookRoot + '"');

let scpConfig = this._sshConfig || {};
scpConfig.path = remotePlaybookRoot;
tl.debug('Copying playbook to ansible machine.');
this._playbookPath = remotePlaybookRoot;
this._playbookPath = remotePlaybookRoot + "/" + playbookFile;
this._cleanupCmd.push('rm -rf ' + remotePlaybookRoot);
await ansibleUtils.copyFileToRemoteMachine(playbookFullPath,remotePlaybookRoot, scpConfig);
await ansibleUtils.copyFileToRemoteMachine(playbookRoot, remotePlaybookRoot, scpConfig);
}

private async copyInventoryAndSetPathForAgentAsSource() {
Expand Down
34 changes: 31 additions & 3 deletions Extensions/Ansible/Src/Tasks/Ansible/ansibleUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tl = require("azure-pipelines-task-lib/task");
import Q = require("q");
import util = require("util");
const fs = require('fs');
import querystring = require('querystring');
import * as SftpClient from 'ssh2-sftp-client';

Expand Down Expand Up @@ -35,11 +36,38 @@ export async function copyFileToRemoteMachine(src: string, dest: string, sftpCon

try {
await sftpClient.connect(sftpConfig);
await sftpClient.put(src, dest);
tl.debug('Copied script file to remote machine at: ${dest}');

// Upload
const isDirectory = fs.lstatSync(src).isDirectory();

if (isDirectory) {
// Make sure the remote directory exists
try {
await sftpClient.mkdir(dest, true); // recursive = true
} catch (err) {
if (err.code !== 4 && !err.message.includes('Failure')) {
throw err;
}
// Check if directory really exists
await sftpClient.stat(dest);
console.log(`Remote directory exists: ${dest}`);
}
tl.debug(`Copying directory to remote machine at: ${dest}`);
await sftpClient.uploadDir(src, dest);
tl.debug(`Copied directory to remote machine at: ${dest}`);
} else {
tl.debug(`Copying file to remote machine at: ${dest}`);
try {
await sftpClient.put(src, dest);
} catch (err) {
console.error('PUT failed:', err.message);
}
tl.debug(`Copied file to remote machine at: ${dest}`);
}

defer.resolve('0');
} catch (err) {
defer.reject(tl.loc('RemoteCopyFailed', err));
defer.reject(tl.loc('RemoteCopyFailed', err));
}

try {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Ansible/Src/Tasks/Ansible/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 0,
"Minor": 256,
"Patch": 0
"Patch": 5
},
"demands": [],
"instanceNameFormat": "Run playbook",
Expand Down
2 changes: 1 addition & 1 deletion Extensions/Ansible/Src/vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "vss-services-ansible",
"name": "Ansible",
"publisher": "ms-vscs-rm",
"version": "0.256.2",
"version": "0.256.5",
"public": true,
"description": "This extension executes an Ansible playbook using a specified inventory via command line interface",
"_description.comment": "The below format to define extensions is currently in preview and may change in future.",
Expand Down