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

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

Instance Method Summary collapse

Constructor Details

#initialize(input, suspended_action:) ⇒ AnsibleRunner

Returns a new instance of AnsibleRunner.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 11

def initialize(input, suspended_action:)
  super input, :suspended_action => suspended_action
  @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]
end

Instance Method Details

#closeObject



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

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

#refreshObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 31

def refresh
  return unless super
  @counter ||= 1
  @uuid ||= File.basename(Dir["#{@root}/artifacts/*"].first)
  job_event_dir = File.join(@root, 'artifacts', @uuid, 'job_events')
  loop do
    files = Dir["#{job_event_dir}/*.json"].map do |file|
      num = File.basename(file)[/\A\d+/].to_i unless file.include?('partial')
      [file, num]
    end
    files_with_nums = files.select { |(_, num)| num && num >= @counter }.sort_by(&:last)
    break if files_with_nums.empty?
    logger.debug("[foreman_ansible] - processing event files: #{files_with_nums.map(&:first).inspect}}")
    files_with_nums.map(&:first).each { |event_file| handle_event_file(event_file) }
    @counter = files_with_nums.last.last + 1
  end
end

#startObject



24
25
26
27
28
29
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 24

def start
  prepare_directory_structure
  write_inventory
  write_playbook
  start_ansible_runner
end