diff --git a/docs/index.html b/docs/index.html index e8fc158..34e2b5a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -193,7 +193,10 @@
command.asSudo();--become
+ + +command.asBecome();-k
@@ -207,8 +210,6 @@command.askSudoPass();verbose level: accepts any level supported by the CLI
diff --git a/lib/ansible.js b/lib/ansible.js index 4bb7e87..ef03589 100644 --- a/lib/ansible.js +++ b/lib/ansible.js @@ -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) @@ -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"); @@ -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; }; @@ -320,4 +333,4 @@ var Playbook = function () { inherits(Playbook, AbstractAnsibleCommand); module.exports.AdHoc = AdHoc; -module.exports.Playbook = Playbook; +module.exports.Playbook = Playbook; \ No newline at end of file diff --git a/test/adhoc.spec.js b/test/adhoc.spec.js index 56d4fc1..6fa717b 100644 --- a/test/adhoc.spec.js +++ b/test/adhoc.spec.js @@ -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) {