Class: Proxy::Ansible::Runner::Playbook

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

Overview

Implements Proxy::Dynflow::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.



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

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.



14
15
16
# File 'lib/smart_proxy_ansible/runner/playbook.rb', line 14

def command_in
  @command_in
end

#command_outObject (readonly)

Returns the value of attribute command_out.



14
15
16
# File 'lib/smart_proxy_ansible/runner/playbook.rb', line 14

def command_out
  @command_out
end

#command_pidObject (readonly)

Returns the value of attribute command_pid.



14
15
16
# File 'lib/smart_proxy_ansible/runner/playbook.rb', line 14

def command_pid
  @command_pid
end

Instance Method Details

#closeObject



47
48
49
50
# File 'lib/smart_proxy_ansible/runner/playbook.rb', line 47

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

#killObject



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

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

#startObject



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

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