Skip to content

Commit

Permalink
Add validations for the ansible-runner params
Browse files Browse the repository at this point in the history
Add validations for the ansible-runner params

Fixes ManageIQ#17737
  • Loading branch information
Ladas committed Jul 24, 2018
1 parent 9824734 commit be55b14
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/ansible/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def run_queue(env_vars, extra_vars, playbook_path, user_id, queue_opts)
private

def run_via_cli(env_vars, extra_vars, playbook_path)
validate_params!(env_vars, extra_vars, playbook_path)

Dir.mktmpdir("ansible-runner") do |base_dir|
Dir.mkdir(File.join(base_dir, 'project')) # without this, there is a silent fail of the ansible-runner command see https://github.com/ansible/ansible-runner/issues/88

Expand All @@ -45,6 +47,24 @@ def return_code(base_dir)
1
end

def validate_params!(env_vars, extra_vars, playbook_path)
assert_hash!(env_vars)
assert_hash!(extra_vars)
assert_path!(playbook_path)
end

def assert_hash!(hash)
unless hash.kind_of?(Hash)
raise "Passed parameter must be of type Hash, got: #{hash}"
end
end

def assert_path!(path)
unless File.exist?(path)
raise "File doesn't exist: #{path}"
end
end

def ansible_command(base_dir)
# TODO add possibility to use custom path, e.g. from virtualenv
"ansible-runner run #{base_dir} --json -i result"
Expand Down

0 comments on commit be55b14

Please sign in to comment.