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
6 changes: 6 additions & 0 deletions lib/ansible.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ AbstractAnsibleCommand.prototype.asSudo = function() {
return this;
};

AbstractAnsibleCommand.prototype.vaultPasswordFile = function(vaultPasswordFile) {
this.config.vaultPasswordFile = vaultPasswordFile;
return this;
};

AbstractAnsibleCommand.prototype.addParam = function(commandParams, param, flag) {
if (this.config[param]) {
return this.addParamValue(commandParams, this.config[param], flag)
Expand Down Expand Up @@ -143,6 +148,7 @@ AbstractAnsibleCommand.prototype.commonCompileParams = function(commandParams) {
commandParams = this.addParam(commandParams, "limit", "l");
commandParams = this.addParam(commandParams, "su", "U");
commandParams = this.addPathParam(commandParams, "privateKey", "-private-key");
commandParams = this.addParam(commandParams, "vaultPasswordFile", "-vault-password-file");
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use addPathParam() instead of addParam(). However, when I tried using addPathParam(), I got this error

ERROR! The vault password file /srv/ansible_api/"/srv/ansible/test.txt" was not found

/srv/ansible_api/ is the working directory, and /srv/ansible/test.txt is the value I passed into the vaultPasswordFile() function.

addPathParam() works when passing a filename into privateKey(), so I'm not sure why it doesn't work with vaultPasswordFile().

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that addPathParam() is not working for the same reason of #28

commandParams = this.addVerbose(commandParams);
commandParams = this.addSudo(commandParams);

Expand Down
11 changes: 11 additions & 0 deletions test/adhoc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ describe('AdHoc command', function() {
})
})

describe('with vault password file', function() {

it('should contain vault password file in execution', function(done) {
var command = new AdHoc().module('shell').hosts('local').args("echo 'hello'").vaultPasswordFile("/vault.txt");
expect(command.exec()).to.be.fulfilled.then(function() {
expect(spawnSpy).to.be.calledWith('ansible', ['local', '-m', 'shell', '-a', 'echo \'hello\'', '--vault-password-file', '/vault.txt']);
done();
}).done();
})
})

after(function() {
process.spawn = oldSpawn;
spawnSpy.restore();
Expand Down
12 changes: 12 additions & 0 deletions test/playbook.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ describe('Playbook command', function () {

})

describe('with vault password file', function() {

it('should execute the playbook with specified vault password file', function (done) {
var command = new Playbook().playbook('test').vaultPasswordFile("/vault.txt");
expect(command.exec()).to.be.fulfilled.then(function () {
expect(spawnSpy).to.be.calledWith('ansible-playbook' ,['test.yml', '--vault-password-file', '/vault.txt']);
done();
}).done();
})

})

describe('with working directory', function () {

var path = require('path');
Expand Down