foreman_ansible_core 4.0.0 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6427ec31aba5a41a3ffa93168c761218f0aff53f97d08681c9d2cba431b50a9f
4
- data.tar.gz: cc0a584af7801a24e3d66b679b840c968ab7851f38901abf37e5d26923d1eea9
3
+ metadata.gz: 1ca3b309e4ee2869e3eeca882b6e296a68728ec7f6722ff294dcba365c912ffc
4
+ data.tar.gz: 6215aa8ddb560b6d140873c7c390af83cca70af62a0a8571cf51f1d6b6db0bae
5
5
  SHA512:
6
- metadata.gz: 1f4db115d787db1dc78d3eaa468b2972514005aa8d068fc0b98d73f7a07e159a5646a9cff4e5f9a19ed6de1ee4043f9f04379f69e82bdceb6a1b9ab5d8257f60
7
- data.tar.gz: bb6bb793c4ea5d2f43af3ac1c3e545f39b574f32041cd141cd06e4c115e519c3e221449a7af0b4956627acf593792b63376d54dc922bd0ff69ba13ecd76924aa
6
+ metadata.gz: 8d507685ceb4cc8278ae333d4edc12fabd45a998123dd3c69158b88b0c7bd987ec792bd76b59b75f43e77a2b2db066595c3582895f6d9cf1be69bd6b36ac9ae7
7
+ data.tar.gz: 8968f788db24c21d1222d9c0729f88371d7469910c3429335290d6fd72cfbad4a9084373a227b27a4d72188de6abce473d7e3121838efdf7afaeb35b5c947e8b
@@ -8,9 +8,12 @@ module ForemanAnsibleCore
8
8
  def initialize(input, suspended_action:)
9
9
  super input, :suspended_action => suspended_action
10
10
  @inventory = rebuild_secrets(rebuild_inventory(input), input)
11
- @playbook = input.values.first[:input][:action_input][:script]
11
+ action_input = input.values.first[:input][:action_input]
12
+ @playbook = action_input[:script]
12
13
  @root = working_dir
13
- @verbosity_level = input.values.first[:input][:action_input][:verbosity_level]
14
+ @verbosity_level = action_input[:verbosity_level]
15
+ @rex_command = action_input[:remote_execution_command]
16
+ @check_mode = action_input[:check_mode]
14
17
  end
15
18
 
16
19
  def start
@@ -77,10 +80,17 @@ module ForemanAnsibleCore
77
80
  def handle_broadcast_data(event)
78
81
  log_event("broadcast", event)
79
82
  if event['event'] == 'playbook_on_stats'
83
+ failures = event.dig('event_data', 'failures') || {}
84
+ unreachable = event.dig('event_data', 'dark') || {}
80
85
  header, *rows = event['stdout'].strip.lines.map(&:chomp)
81
86
  @outputs.keys.select { |key| key.is_a? String }.each do |host|
82
87
  line = rows.find { |row| row =~ /#{host}/ }
83
88
  publish_data_for(host, [header, line].join("\n"), 'stdout')
89
+
90
+ # If the task has been rescued, it won't consider a failure
91
+ if @exit_statuses[host].to_i != 0 && failures[host].to_i <= 0 && unreachable[host].to_i <= 0
92
+ publish_exit_status_for(host, 0)
93
+ end
84
94
  end
85
95
  else
86
96
  broadcast_data(event['stdout'] + "\n", 'stdout')
@@ -104,7 +114,10 @@ module ForemanAnsibleCore
104
114
  end
105
115
 
106
116
  def start_ansible_runner
107
- command = ['ansible-runner', 'run', @root, '-p', 'playbook.yml']
117
+ env = {}
118
+ env['FOREMAN_CALLBACK_DISABLE'] = '1' if @rex_command
119
+ command = [env, 'ansible-runner', 'run', @root, '-p', 'playbook.yml']
120
+ command << '--cmdline' << '"--check"' if check_mode?
108
121
  command << verbosity if verbose?
109
122
  initialize_command(*command)
110
123
  logger.debug("[foreman_ansible] - Running command '#{command.join(' ')}'")
@@ -118,6 +131,10 @@ module ForemanAnsibleCore
118
131
  @verbosity_level.to_i.positive?
119
132
  end
120
133
 
134
+ def check_mode?
135
+ @check_mode == true
136
+ end
137
+
121
138
  def prepare_directory_structure
122
139
  inner = %w[inventory project].map { |part| File.join(@root, part) }
123
140
  ([@root] + inner).each do |path|
@@ -138,7 +155,12 @@ module ForemanAnsibleCore
138
155
  action_inputs = input.values.map { |hash| hash[:input][:action_input] }
139
156
  hostnames = action_inputs.map { |hash| hash[:name] }
140
157
  inventories = action_inputs.map { |hash| hash[:ansible_inventory] }
141
- host_vars = inventories.map { |i| i['_meta']['hostvars'] }.reduce(&:merge)
158
+ host_vars = inventories.map { |i| i['_meta']['hostvars'] }.reduce({}) do |acc, hosts|
159
+ hosts.reduce(acc) do |inner_acc, (hostname, vars)|
160
+ vars[:ansible_ssh_private_key_file] ||= ForemanRemoteExecutionCore.settings[:ssh_identity_key_file]
161
+ inner_acc.merge(hostname => vars)
162
+ end
163
+ end
142
164
 
143
165
  { '_meta' => { 'hostvars' => host_vars },
144
166
  'all' => { 'hosts' => hostnames,
@@ -17,6 +17,12 @@ module ForemanAnsibleCore
17
17
  Runner::AnsibleRunner
18
18
  end
19
19
 
20
+ # Discard everything apart from hostname to be able to tell the actions
21
+ # apart when debugging
22
+ def transform_input(input)
23
+ { 'action_input' => super['action_input'].slice('name', :task_id) }
24
+ end
25
+
20
26
  # def self.input_format
21
27
  # {
22
28
  # $UUID => {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanAnsibleCore
4
- VERSION = '4.0.0'
4
+ VERSION = '4.1.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_ansible_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman_remote_execution_core
@@ -77,7 +77,7 @@ homepage: https://github.com/theforeman/foreman_ansible
77
77
  licenses:
78
78
  - GPL-3.0
79
79
  metadata: {}
80
- post_install_message:
80
+ post_install_message:
81
81
  rdoc_options: []
82
82
  require_paths:
83
83
  - lib
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubygems_version: 3.1.2
96
- signing_key:
96
+ signing_key:
97
97
  specification_version: 4
98
98
  summary: 'Ansible integration with Foreman (theforeman.org): core bits'
99
99
  test_files: []