Class: ForemanAnsibleCore::RemoteExecutionCore::AnsibleRunner

Inherits:
ForemanTasksCore::Runner::CommandRunner
  • Object
show all
Defined in:
lib/foreman_ansible_core/remote_execution_core/ansible_runner.rb

Overview

Takes an inventory and runs it through REXCore CommandRunner

Constant Summary collapse

DEFAULT_REFRESH_INTERVAL =
1
CONNECTION_PROMPT =
'Are you sure you want to continue connecting (yes/no)? '

Instance Method Summary collapse

Constructor Details

#initialize(options, suspended_action:) ⇒ AnsibleRunner

Returns a new instance of AnsibleRunner.



10
11
12
13
14
15
16
17
18
# File 'lib/foreman_ansible_core/remote_execution_core/ansible_runner.rb', line 10

def initialize(options, suspended_action:)
  super(options, :suspended_action => suspended_action)
  @playbook_runner = ForemanAnsibleCore::Runner::Playbook.new(
    options['ansible_inventory'],
    options['script'],
    options,
    :suspended_action => suspended_action
  )
end

Instance Method Details

#fill_continuous_output(continuous_output) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/foreman_ansible_core/remote_execution_core/ansible_runner.rb', line 31

def fill_continuous_output(continuous_output)
  delegated_output.fetch('result', []).each do |raw_output|
    continuous_output.add_raw_output(raw_output)
  end
rescue StandardError => e
  continuous_output.add_exception(_('Error loading data from proxy'), e)
end

#killObject



47
48
49
50
51
# File 'lib/foreman_ansible_core/remote_execution_core/ansible_runner.rb', line 47

def kill
  publish_exit_status(1)
  ::Process.kill('SIGTERM', @command_pid)
  close
end

#refreshObject



39
40
41
42
43
44
45
# File 'lib/foreman_ansible_core/remote_execution_core/ansible_runner.rb', line 39

def refresh
  @command_out = @playbook_runner.command_out
  @command_in = @playbook_runner.command_in
  @command_pid = @playbook_runner.command_pid
  super
  kill if unknown_host_key_fingerprint?
end

#startObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/foreman_ansible_core/remote_execution_core/ansible_runner.rb', line 20

def start
  @playbook_runner.logger = logger
  @playbook_runner.start
rescue StandardError => e
  logger.error(
    'error while initalizing command'\
    " #{e.class} #{e.message}:\n #{e.backtrace.join("\n")}"
  )
  publish_exception('Error initializing command', e)
end