From be55b14f5ec12abe8404f0b6b1abf665bc6520f6 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Tue, 24 Jul 2018 09:41:28 +0200 Subject: [PATCH] Add validations for the ansible-runner params Add validations for the ansible-runner params Fixes https://github.com/ManageIQ/manageiq/issues/17737 --- lib/ansible/runner.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/ansible/runner.rb b/lib/ansible/runner.rb index d2933ae1172..815e8bd8e99 100644 --- a/lib/ansible/runner.rb +++ b/lib/ansible/runner.rb @@ -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 @@ -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"