Class: ForemanAnsibleCore::Runner::AnsibleRunner
- Inherits:
-
ForemanTasksCore::Runner::Parent
- Object
- ForemanTasksCore::Runner::Parent
- ForemanAnsibleCore::Runner::AnsibleRunner
- Includes:
- ForemanTasksCore::Runner::Command
- Defined in:
- lib/foreman_ansible_core/runner/ansible_runner.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(input, suspended_action:) ⇒ AnsibleRunner
constructor
A new instance of AnsibleRunner.
- #refresh ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(input, suspended_action:) ⇒ AnsibleRunner
Returns a new instance of AnsibleRunner.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/foreman_ansible_core/runner/ansible_runner.rb', line 9 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] @passphrase = action_input['secrets']['key_passphrase'] end |
Instance Method Details
#close ⇒ Object
47 48 49 50 |
# File 'lib/foreman_ansible_core/runner/ansible_runner.rb', line 47 def close super FileUtils.remove_entry(@root) if @tmp_working_dir end |
#refresh ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/foreman_ansible_core/runner/ansible_runner.rb', line 29 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 |
#start ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/foreman_ansible_core/runner/ansible_runner.rb', line 21 def start prepare_directory_structure write_inventory write_playbook write_ssh_key if !@passphrase.nil? && !@passphrase.empty? start_ansible_runner end |