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
31
32
33
# 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]
  @job_check_mode = action_input[:job_check_mode]
  @diff_mode = action_input[:diff_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)
  prune_known_hosts_on_first_execution
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



66
67
68
69
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 66

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

#initialize_command(*command) ⇒ Object



77
78
79
80
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 77

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

#killObject



59
60
61
62
63
64
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 59

def kill
  ::Process.kill('SIGTERM', @process_manager.pid)
  @inventory['all']['hosts'].each_key { |hostname| @exit_statuses[hostname] = 2 }
  publish_exit_status(2)
  close
end

#publish_exit_status(status) ⇒ Object



71
72
73
74
75
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 71

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



43
44
45
46
47
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 43

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

#startObject



35
36
37
38
39
40
41
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 35

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

#timeoutObject



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

def timeout
  logger.debug('job timed out')
  broadcast_data('Timeout for execution passed, stopping the job', 'stderr')
  super
end

#timeout_intervalObject



55
56
57
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 55

def timeout_interval
  execution_timeout_interval
end