From 4d0eab2d8e59eb62a7bac45d39dc8bcc78bf5203 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Mon, 16 Aug 2021 09:28:59 -0500 Subject: [PATCH] [Ansible::Runner] Set ANSIBLE_STDOUT_CALLBACK This allows getting rid of this setting in a config value in the appliance: https://github.com/ManageIQ/manageiq-appliance/blob/a6758392ea32b71307828f868db6407be0858a12/LINK/root/.ansible.cfg#L2 Which frees up the potential of removing that file all together. --- lib/ansible/runner.rb | 23 ++++++++++++++--------- spec/lib/ansible/runner_spec.rb | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/ansible/runner.rb b/lib/ansible/runner.rb index 17487e4b127..73a5ddad931 100644 --- a/lib/ansible/runner.rb +++ b/lib/ansible/runner.rb @@ -206,7 +206,7 @@ def run_via_cli(hosts, credentials, env_vars, extra_vars, tags: nil, ansible_run end command_line_hash.merge!(cred_command_line) - env_vars_hash = env_vars.merge(cred_env_vars).merge(python_env) + env_vars_hash = env_vars.merge(cred_env_vars).merge(runner_env) extra_vars_hash = extra_vars.merge(cred_extra_vars) create_hosts_file(base_dir, hosts) @@ -305,14 +305,11 @@ def fetch_galaxy_roles(playbook_or_role_args) Ansible::Content.new(playbook_dir).fetch_galaxy_roles end - def python_env - if python3_modules_path.present? - { "PYTHONPATH" => python3_modules_path } - elsif python2_modules_path.present? - { "PYTHONPATH" => python2_modules_path } - else - {} - end + def runner_env + { + "ANSIBLE_STDOUT_CALLBACK" => "json", + "PYTHONPATH" => python_path + }.delete_nils end def credentials_info(credentials, base_dir) @@ -387,6 +384,14 @@ def wait_for(path, timeout: 10.seconds) res end + def python_path + if python3_modules_path.present? + python3_modules_path + else + python2_modules_path + end + end + PYTHON2_MODULE_PATHS = %w[ /var/lib/manageiq/venv/lib/python2.7/site-packages ].freeze diff --git a/spec/lib/ansible/runner_spec.rb b/spec/lib/ansible/runner_spec.rb index a3288ad2b7f..731d1bcdc47 100644 --- a/spec/lib/ansible/runner_spec.rb +++ b/spec/lib/ansible/runner_spec.rb @@ -98,7 +98,17 @@ described_class.run(env_vars, extra_vars, playbook, :become_enabled => true) end - it "sets PYTHONPATH correctly with python3 awx modules only installed " do + it "sets ANSIBLE_STDOUT_CALLBACK to json" do + expect(AwesomeSpawn).to receive(:run) do |command, options| + expect(command).to eq("ansible-runner") + + expect(options[:env]["ANSIBLE_STDOUT_CALLBACK"]).to eq("json") + end.and_return(result) + + described_class.run(env_vars, extra_vars, playbook) + end + + it "sets PYTHONPATH correctly with python3 awx modules only installed" do allow(File).to receive(:exist?).with(python2_modules_path).and_return(false) allow(File).to receive(:exist?).with(python3_modules_path).and_return(false) allow(File).to receive(:exist?).with(py3_awx_modules_path).and_return(true) @@ -112,7 +122,7 @@ described_class.run(env_vars, extra_vars, playbook, :become_enabled => true) end - it "sets PYTHONPATH correctly with python2 modules installed " do + it "sets PYTHONPATH correctly with python2 modules installed" do allow(File).to receive(:exist?).with(python2_modules_path).and_return(true) allow(File).to receive(:exist?).with(python3_modules_path).and_return(false) allow(File).to receive(:exist?).with(py3_awx_modules_path).and_return(false)