Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #35456 - Source environment before starting ansible-runner #66

Merged
merged 5 commits into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/smart_proxy_ansible/plugin.rb
Expand Up @@ -5,7 +5,8 @@ class Plugin < Proxy::Plugin
rackup_path File.expand_path('http_config.ru', __dir__)
settings_file 'ansible.yml'
plugin :ansible, Proxy::Ansible::VERSION
default_settings :ansible_dir => Dir.home
default_settings :ansible_dir => Dir.home,
:ansible_environment_file => '/etc/foreman-proxy/ansible.env'
# :working_dir => nil

load_classes ::Proxy::Ansible::ConfigurationLoader
Expand Down
14 changes: 12 additions & 2 deletions lib/smart_proxy_ansible/runner/ansible_runner.rb
Expand Up @@ -186,10 +186,20 @@ def write_ssh_key
def start_ansible_runner
env = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in theforeman/puppet-foreman_proxy#777 (comment) I wonder if we should present everything as environment variables by default. In that case I'd probably extract the env var construction to a separate method.

env['FOREMAN_CALLBACK_DISABLE'] = '1' if @rex_command
ekohl marked this conversation as resolved.
Show resolved Hide resolved
command = [env, 'ansible-runner', 'run', @root, '-p', 'playbook.yml']
command = ['ansible-runner', 'run', @root, '-p', 'playbook.yml']
command << '--cmdline' << cmdline unless cmdline.nil?
command << verbosity if verbose?
initialize_command(*command)

ansible_env = Proxy::Ansible::Plugin.settings[:ansible_environment_file].shellescape
init = <<~EOF
#!/bin/sh
[ -f #{ansible_env} ] && source #{ansible_env}
exec #{command.map(&:shellescape).join(' ')}
EOF
init_path = File.join(@root, 'init.sh')
File.write(init_path, init, { perm: 0o0755 })
ekohl marked this conversation as resolved.
Show resolved Hide resolved

initialize_command(env, init_path)
logger.debug("[foreman_ansible] - Running command '#{command.join(' ')}'")
end

Expand Down
1 change: 1 addition & 0 deletions settings.d/ansible.yml.example
@@ -1,3 +1,4 @@
---
:enabled: true
:working_dir: '~/.foreman-ansible'
# :ansible_environment_file: /etc/foreman-proxy/ansible.env