Class: Proxy::Ansible::Runner::AnsibleRunner
- Inherits:
-
Dynflow::Runner::Parent
- Object
- Dynflow::Runner::Parent
- Proxy::Ansible::Runner::AnsibleRunner
- Includes:
- Dynflow::Runner::ProcessManagerCommand
- Defined in:
- lib/smart_proxy_ansible/runner/ansible_runner.rb
Constant Summary collapse
- ENVIRONMENT_WRAPPER =
To make this overridable in development
ENV['SMART_PROXY_ANSIBLE_ENVIRONMENT_WRAPPER'] || '/usr/libexec/foreman-proxy/ansible-runner-environment'
Instance Attribute Summary collapse
-
#execution_timeout_interval ⇒ Object
readonly
Returns the value of attribute execution_timeout_interval.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(input, suspended_action:, id: nil) ⇒ AnsibleRunner
constructor
A new instance of AnsibleRunner.
- #initialize_command(*command) ⇒ Object
- #kill ⇒ Object
- #publish_exit_status(status) ⇒ Object
- #run_refresh_output ⇒ Object
- #start ⇒ Object
- #timeout ⇒ Object
- #timeout_interval ⇒ Object
Constructor Details
#initialize(input, suspended_action:, id: nil) ⇒ AnsibleRunner
Returns a new instance of AnsibleRunner.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 16 def initialize(input, suspended_action:, id: nil) super input, :suspended_action => suspended_action, :id => id @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] @passphrase = action_input['secrets']['key_passphrase'] @execution_timeout_interval = action_input[:execution_timeout_interval] @cleanup_working_dirs = action_input.fetch(:cleanup_working_dirs, true) end |
Instance Attribute Details
#execution_timeout_interval ⇒ Object (readonly)
Returns the value of attribute execution_timeout_interval.
11 12 13 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 11 def execution_timeout_interval @execution_timeout_interval end |
Instance Method Details
#close ⇒ Object
63 64 65 66 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 63 def close super FileUtils.remove_entry(@root) if @tmp_working_dir && Dir.exist?(@root) && @cleanup_working_dirs end |
#initialize_command(*command) ⇒ Object
74 75 76 77 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 74 def initialize_command(*command) super @process_manager.stdin.close unless @process_manager.done? end |
#kill ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 55 def kill ::Process.kill('SIGTERM', @process_manager.pid) publish_exit_status(2) @inventory['all']['hosts'].each { |hostname| @exit_statuses[hostname] = 2 } broadcast_data('Timeout for execution passed, stopping the job', 'stderr') close end |
#publish_exit_status(status) ⇒ Object
68 69 70 71 72 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 68 def publish_exit_status(status) process_artifacts super @targets.each_key { |host| publish_exit_status_for(host, @exit_statuses[host]) } if status != 0 end |
#run_refresh_output ⇒ Object
40 41 42 43 44 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 40 def run_refresh_output logger.debug('refreshing runner on demand') process_artifacts generate_updates end |
#start ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 32 def start prepare_directory_structure write_inventory write_playbook write_ssh_key if !@passphrase.nil? && !@passphrase.empty? start_ansible_runner end |
#timeout ⇒ Object
46 47 48 49 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 46 def timeout logger.debug('job timed out') super end |
#timeout_interval ⇒ Object
51 52 53 |
# File 'lib/smart_proxy_ansible/runner/ansible_runner.rb', line 51 def timeout_interval execution_timeout_interval end |