Skip to content

Commit

Permalink
[Ansible::Runner] Set ANSIBLE_STDOUT_CALLBACK
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NickLaMuro committed Aug 16, 2021
1 parent c83f5ae commit 4d0eab2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
23 changes: 14 additions & 9 deletions lib/ansible/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions spec/lib/ansible/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 4d0eab2

Please sign in to comment.