Skip to content

Commit

Permalink
Add limit support
Browse files Browse the repository at this point in the history
Add support for --limit
  • Loading branch information
evilr00t committed Feb 26, 2020
1 parent 289dc4d commit 136f2ba
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Most parameters map directly to `ansible-playbook` options. See the
templates, show the differences in those files; works great with `check: true`.
* `inventory`: Required. The path to the inventory file to use, relative
to `path`.
* `limit`: Optional. Limit the playbook run to provided hosts/groups.
* `playbook`: Optional. Default `site.yml`. The path to the playbook file to run,
relative to `path`.
* `skip_tags`: Optional. Only run plays and tasks not tagged with this list of values.
Expand Down
6 changes: 6 additions & 0 deletions assets/lib/ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AnsiblePlaybook
attr_writer :env
attr_writer :extra_vars
attr_writer :inventory
attr_writer :limit
attr_writer :playbook
attr_writer :private_key
attr_writer :skip_tags
Expand Down Expand Up @@ -52,6 +53,10 @@ def extra_vars
"--extra-vars '#{@extra_vars.to_json}'" unless @extra_vars.nil?
end

def limit
"--limit '#{@limit}'" unless @limit.nil?
end

def inventory
raise "inventory required" if @inventory.nil?
"-i #{@inventory}"
Expand Down Expand Up @@ -99,6 +104,7 @@ def command
diff,
extra_vars,
inventory,
limit,
private_key,
skip_tags,
ssh_common_args,
Expand Down
1 change: 1 addition & 0 deletions assets/lib/commands/out.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def run_playbook!
ap.diff = params.diff
ap.env = ENV.to_hash.merge(source.env || {})
ap.extra_vars = params.vars
ap.limit = params.limit
ap.inventory = require_param 'inventory'
ap.playbook = params.playbook
ap.private_key = SSH_KEY_PATH
Expand Down
33 changes: 33 additions & 0 deletions spec/integration/playbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,39 @@
]
end

it "calls ansible-playbook with params.limit" do
stdin = {
"source" => {
"ssh_private_key" => "key",
"verbose" => "vv"
},
"params" => {
"path" => "spec/fixtures",
"inventory" => "the_inventory",
"limit" => "foobar"
}
}.to_json

stdout, stderr, status = Open3.capture3("#{out_file} .", :stdin_data => stdin)

expect(status.success?).to be true

out = JSON.parse(File.read(mockelton_out))

expect(out["sequence"].size).to be 2
expect(out["sequence"][1]["exec-spec"]["args"]).to eq [
"ansible-playbook",
"-i",
"the_inventory",
"--limit",
"foobar",
"--private-key",
ssh_private_key_file,
"-vv",
"site.yml"
]
end

it "runs setup_commands" do
stdin = {
"source" => {
Expand Down

0 comments on commit 136f2ba

Please sign in to comment.