Skip to content

Commit

Permalink
Refs #35456 - Expect the wrapper to exist on filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Aug 30, 2022
1 parent 2f7b660 commit fc161ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 4 additions & 0 deletions bin/ansible-runner-environment.sh
@@ -0,0 +1,4 @@
#!/bin/sh

[ -f "$ANSIBLE_ENVIRONMENT_FILE" ] && source "$ANSIBLE_ENVIRONMENT_FILE"
exec "$@"
15 changes: 5 additions & 10 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/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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit fc161ff

Please sign in to comment.