Class: Proxy::Ansible::Runner::AnsibleRunner

Inherits:
Dynflow::Runner::Parent
  • Object
show all
Includes:
Dynflow::Runner::ProcessManagerCommand
Defined in:
lib/smart_proxy_ansible/runner/ansible_runner.rb

Constant Summary collapse

ENVIRONMENT_WRAPPER =

To make this overridable in development

ENV['SMART_PROXY_ANSIBLE_ENVIRONMENT_WRAPPER'] || '/usr/libexec/foreman-proxy/ansible-runner-environment'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, suspended_action:, id: nil) ⇒ AnsibleRunner

Returns a new instance of AnsibleRunner.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 16

def initialize(input, suspended_action:, id: nil)
  super input, :suspended_action => suspended_action, :id => id
  @inventory = rebuild_secrets(rebuild_inventory(input), input)
  action_input = input.values.first[:input][:action_input]
  @playbook = action_input[:script]
  @root = working_dir
  @verbosity_level = action_input[:verbosity_level]
  @rex_command = action_input[:remote_execution_command]
  @check_mode = action_input[:check_mode]
  @tags = action_input[:tags]
  @tags_flag = action_input[:tags_flag]
  @passphrase = action_input['secrets']['key_passphrase']
  @execution_timeout_interval = action_input[:execution_timeout_interval]
  @cleanup_working_dirs = action_input.fetch(:cleanup_working_dirs, true)
end

Instance Attribute Details

#execution_timeout_intervalObject (readonly)

Returns the value of attribute execution_timeout_interval.



11
12
13
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 11

def execution_timeout_interval
  @execution_timeout_interval
end

Instance Method Details

#closeObject



63
64
65
66
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 63

def close
  super
  FileUtils.remove_entry(@root) if @tmp_working_dir && Dir.exist?(@root) && @cleanup_working_dirs
end

#initialize_command(*command) ⇒ Object



74
75
76
77
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 74

def initialize_command(*command)
  super
  @process_manager.stdin.close unless @process_manager.done?
end

#killObject



55
56
57
58
59
60
61
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 55

def kill
  ::Process.kill('SIGTERM', @process_manager.pid)
  publish_exit_status(2)
  @inventory['all']['hosts'].each { |hostname| @exit_statuses[hostname] = 2 }
  broadcast_data('Timeout for execution passed, stopping the job', 'stderr')
  close
end

#publish_exit_status(status) ⇒ Object



68
69
70
71
72
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 68

def publish_exit_status(status)
  process_artifacts
  super
  @targets.each_key { |host| publish_exit_status_for(host, @exit_statuses[host]) } if status != 0
end

#run_refresh_outputObject



40
41
42
43
44
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 40

def run_refresh_output
  logger.debug('refreshing runner on demand')
  process_artifacts
  generate_updates
end

#startObject



32
33
34
35
36
37
38
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 32

def start
  prepare_directory_structure
  write_inventory
  write_playbook
  write_ssh_key if !@passphrase.nil? && !@passphrase.empty?
  start_ansible_runner
end

#timeoutObject



46
47
48
49
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 46

def timeout
  logger.debug('job timed out')
  super
end

#timeout_intervalObject



51
52
53
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 51

def timeout_interval
  execution_timeout_interval
end