Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support specifying multiple inventories #54

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/ansible.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
"mock-spawn": "^0.2.6",
"q": "~1.0.0",
"underscore": "~1.5.2"
}
},
"files": ["lib"]
}
11 changes: 11 additions & 0 deletions test/adhoc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down