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 all commits
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
4 changes: 4 additions & 0 deletions bin/ansible-runner-environment.sh
@@ -0,0 +1,4 @@
#!/bin/sh
ehelms marked this conversation as resolved.
Show resolved Hide resolved

[ -f "$SMART_PROXY_ANSIBLE_ENVIRONMENT_FILE" ] && source "$SMART_PROXY_ANSIBLE_ENVIRONMENT_FILE"
exec "$@"
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
9 changes: 7 additions & 2 deletions lib/smart_proxy_ansible/runner/ansible_runner.rb
Expand Up @@ -10,6 +10,9 @@ class AnsibleRunner < ::Proxy::Dynflow::Runner::Parent
include ::Proxy::Dynflow::Runner::ProcessManagerCommand
attr_reader :execution_timeout_interval

# To make this overridable in development
ENVIRONMENT_WRAPPER = ENV['SMART_PROXY_ANSIBLE_ENVIRONMENT_WRAPPER'] || '/usr/libexec/foreman-proxy/ansible-runner-environment'
Copy link
Member

Choose a reason for hiding this comment

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

This is missing the .sh file extension

Copy link
Member

Choose a reason for hiding this comment

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

It really shouldn't ;)
#66 (comment)


def initialize(input, suspended_action:, id: nil)
super input, :suspended_action => suspended_action, :id => id
@inventory = rebuild_secrets(rebuild_inventory(input), input)
Expand Down Expand Up @@ -186,10 +189,12 @@ 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']
env['SMART_PROXY_ANSIBLE_ENVIRONMENT_FILE'] = Proxy::Ansible::Plugin.settings[:ansible_environment_file]
command = ['ansible-runner', 'run', @root, '-p', 'playbook.yml']
command << '--cmdline' << cmdline unless cmdline.nil?
command << verbosity if verbose?
initialize_command(*command)

initialize_command(env, ENVIRONMENT_WRAPPER, *command)
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
3 changes: 2 additions & 1 deletion smart_proxy_ansible.gemspec
Expand Up @@ -19,7 +19,8 @@ Gem::Specification.new do |gem|
'LICENSE', 'README.md',
'lib/smart_proxy_ansible.rb',
'lib/smart_proxy_ansible/**/*',
'bin/json_inventory.sh']
'bin/json_inventory.sh',
'bin/ansible-runner-environment.sh']
gem.extra_rdoc_files = ['README.md', 'LICENSE']
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ['lib']
Expand Down