diff --git a/bin/ansible-runner-environment.sh b/bin/ansible-runner-environment.sh new file mode 100755 index 0000000..5f8cbdc --- /dev/null +++ b/bin/ansible-runner-environment.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +[ -f "$ANSIBLE_ENVIRONMENT_FILE" ] && source "$ANSIBLE_ENVIRONMENT_FILE" +exec "$@" diff --git a/lib/smart_proxy_ansible/runner/ansible_runner.rb b/lib/smart_proxy_ansible/runner/ansible_runner.rb index a715b64..c5d1013 100644 --- a/lib/smart_proxy_ansible/runner/ansible_runner.rb +++ b/lib/smart_proxy_ansible/runner/ansible_runner.rb @@ -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/ansible-runner-environment' + def initialize(input, suspended_action:, id: nil) super input, :suspended_action => suspended_action, :id => id @inventory = rebuild_secrets(rebuild_inventory(input), input) @@ -186,20 +189,12 @@ def write_ssh_key def start_ansible_runner env = {} env['FOREMAN_CALLBACK_DISABLE'] = '1' if @rex_command + env['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? - 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 }) - - initialize_command(env, init_path) + initialize_command(env, ENVIRONMENT_WRAPPER, *command) logger.debug("[foreman_ansible] - Running command '#{command.join(' ')}'") end