From 6f38ec194d277b939e59c5faf5b3658f0f668654 Mon Sep 17 00:00:00 2001 From: Shankar Date: Mon, 14 Jun 2021 18:07:33 +0530 Subject: [PATCH 1/2] feat(adHoc/become): add become support --- lib/ansible.js | 15 ++++++++++++++- test/adhoc.spec.js | 11 +++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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) { From 71b9770469d0e8b01469de6acd40996693fa822f Mon Sep 17 00:00:00 2001 From: Shankar Date: Mon, 14 Jun 2021 18:10:36 +0530 Subject: [PATCH 2/2] doc(AdHoc/become): add become support --- docs/index.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 @@

Supported Flags

command.asSudo();
- +

--become

+ + +
command.asBecome();

-k

@@ -207,8 +210,6 @@

Supported Flags

command.askSudoPass();
- -

verbose level: accepts any level supported by the CLI