diff --git a/examples/index.js b/examples/index.js index 0f9d679..a327cae 100644 --- a/examples/index.js +++ b/examples/index.js @@ -96,6 +96,8 @@ command.forks(4) command.user('root') // -i /etc/ansible/hosts command.inventory('/etc/ansible/hosts') +// -i /etc/ansible/hosts1 -i /etc/ansible/hosts2 +command.inventory(['/etc/ansible/hosts1', '/etc/ansible/hosts2']) // -U root command.su('root'); // --private-key filename diff --git a/lib/ansible.js b/lib/ansible.js index 4bb7e87..1fd8d93 100644 --- a/lib/ansible.js +++ b/lib/ansible.js @@ -105,7 +105,14 @@ AbstractAnsibleCommand.prototype.asSudo = function() { AbstractAnsibleCommand.prototype.addParam = function(commandParams, param, flag) { if (this.config[param]) { - return this.addParamValue(commandParams, this.config[param], flag) + var config = this.config[param]; + if (Array.isArray(config)) { + config.forEach((config_item) => { + commandParams = this.addParamValue(commandParams, config_item, flag); + }) + } else { + commandParams = this.addParamValue(commandParams, config, flag); + } } return commandParams; }; diff --git a/package.json b/package.json index 1fa422f..53fe5b2 100644 --- a/package.json +++ b/package.json @@ -31,5 +31,6 @@ "mock-spawn": "^0.2.6", "q": "~1.0.0", "underscore": "~1.5.2" - } + }, + "files": ["lib"] } diff --git a/test/adhoc.spec.js b/test/adhoc.spec.js index 56d4fc1..428c198 100644 --- a/test/adhoc.spec.js +++ b/test/adhoc.spec.js @@ -134,6 +134,17 @@ describe('AdHoc command', function() { }) }) + describe('with two inventories', function() { + + it('should contain two inventory flags in execution', function(done) { + var command = new AdHoc().module('shell').hosts('local').args("echo 'hello'").inventory(["/etc/my/hosts", "/etc/my/hosts2"]); + expect(command.exec()).to.be.fulfilled.then(function() { + expect(spawnSpy).to.be.calledWith('ansible', ['local', '-m', 'shell', '-a', 'echo \'hello\'', '-i', '/etc/my/hosts', '-i', '/etc/my/hosts2']); + done(); + }).done(); + }) + }) + describe('with inventory subset', function() { it('should execute the playbook with specified inventory subset limit', function (done) {