Class: ForemanAnsibleCore::Runner::Playbook

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

Overview

Implements ForemanTasksCore::Runner::Base interface for running Ansible playbooks, used by the Foreman Ansible plugin and Ansible proxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inventory, playbook, options = {}, suspended_action:) ⇒ Playbook

Returns a new instance of Playbook.



15
16
17
18
19
20
21
22
23
24
# File 'lib/foreman_ansible_core/runner/playbook.rb', line 15

def initialize(inventory, playbook, options = {}, suspended_action:)
  super :suspended_action => suspended_action
  @inventory = rebuild_secrets(inventory, options[:secrets])
  unknown_hosts.each do |host|
    add_to_known_hosts(host)
  end
  @playbook  = playbook
  @options   = options
  initialize_dirs
end

Instance Attribute Details

#command_inObject (readonly)

Returns the value of attribute command_in.



13
14
15
# File 'lib/foreman_ansible_core/runner/playbook.rb', line 13

def command_in
  @command_in
end

#command_outObject (readonly)

Returns the value of attribute command_out.



13
14
15
# File 'lib/foreman_ansible_core/runner/playbook.rb', line 13

def command_out
  @command_out
end

#command_pidObject (readonly)

Returns the value of attribute command_pid.



13
14
15
# File 'lib/foreman_ansible_core/runner/playbook.rb', line 13

def command_pid
  @command_pid
end

Instance Method Details

#closeObject



46
47
48
49
# File 'lib/foreman_ansible_core/runner/playbook.rb', line 46

def close
  super
  FileUtils.remove_entry(@working_dir) if @tmp_working_dir
end

#killObject



39
40
41
42
43
44
# File 'lib/foreman_ansible_core/runner/playbook.rb', line 39

def kill
  publish_data('== TASK ABORTED BY USER ==', 'stdout')
  publish_exit_status(1)
  ::Process.kill('SIGTERM', @command_pid)
  close
end

#startObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/foreman_ansible_core/runner/playbook.rb', line 26

def start
  write_inventory
  write_playbook
  command = CommandCreator.new(inventory_file,
                               playbook_file,
                               @options).command
  logger.debug('[foreman_ansible] - Initializing Ansible Runner')
  Dir.chdir(@ansible_dir) do
    initialize_command(*command)
    logger.debug("[foreman_ansible] - Running command '#{command.join(' ')}'")
  end
end