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
7 changes: 4 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ <h3 id="supported-flags">Supported Flags</h3>

<div class='highlight'><pre>command.asSudo();</pre></div>


<p> --become</p>


<div class='highlight'><pre>command.asBecome();</pre></div>

<p> -k</p>

Expand All @@ -207,8 +210,6 @@ <h3 id="supported-flags">Supported Flags</h3>

<div class='highlight'><pre>command.askSudoPass();</pre></div>



<p>verbose level: accepts any level supported by the CLI</p>


Expand Down
15 changes: 14 additions & 1 deletion 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.asBecome = function() {
this.config.become = true;
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 @@ -136,6 +141,13 @@ AbstractAnsibleCommand.prototype.addSudo = function(commandParams) {
return commandParams;
};

AbstractAnsibleCommand.prototype.addBecome = function(commandParams) {
if (this.config.become) {
commandParams = commandParams.concat('--become');
}
return commandParams;
};

AbstractAnsibleCommand.prototype.commonCompileParams = function(commandParams) {
commandParams = this.addParam(commandParams, "forks", "f");
commandParams = this.addParam(commandParams, "user", "u");
Expand All @@ -145,6 +157,7 @@ AbstractAnsibleCommand.prototype.commonCompileParams = function(commandParams) {
commandParams = this.addPathParam(commandParams, "privateKey", "-private-key");
commandParams = this.addVerbose(commandParams);
commandParams = this.addSudo(commandParams);
commandParams = this.addBecome(commandParams);

return commandParams;
};
Expand Down Expand Up @@ -320,4 +333,4 @@ var Playbook = function () {
inherits(Playbook, AbstractAnsibleCommand);

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

describe('as become', function() {

it('should contain sudo user flag in execution', function(done) {
var command = new AdHoc().module('shell').hosts('local').args("echo 'hello'").asBecome();
expect(command.exec()).to.be.fulfilled.then(function() {
expect(spawnSpy).to.be.calledWith('ansible', ['local', '-m', 'shell', '-a', 'echo \'hello\'', '--become']);
done();
}).done();
})
})

describe('with sudo user specified', function() {

it('should contain sudo user flag in execution', function(done) {
Expand Down