foreman_ansible_core 3.0.5 → 4.1.2

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: 6d8f767c115d90811e6d131c931a3b26759a678b3cebce797735735c99deffb2
4
- data.tar.gz: 7d51f480e657bcc0aaa6bbcfe8d24af0b18772468d384e09fdcacb4b3c13a705
3
+ metadata.gz: f2a3786cc1745dadafd2d12dd0a38dfbb23e0ee19880c3f5bef7eb15c87993a0
4
+ data.tar.gz: 4a31b5d21235e36f4805c2b47e4f4dd6c7baec453393e7f546b2fc7c6ec612a8
5
5
  SHA512:
6
- metadata.gz: fd37c7c252342f558ae43153e0faa5f44c0a568ef5ecdad2a397ef210dc9708aa16627be056cd0b0c4d262aebce7ca95f5685e1f07dda52586530439bf1439c6
7
- data.tar.gz: 0d57f0807a3324a7db4494ef9bc81149d3626b8beac521365be7b21146ee2c32a1f2d026d28af658db731621e78333f2eae6cd5dd8badf2b7e518f57aab78d4b
6
+ metadata.gz: 5ea0819d7adc9d36166f507e3115b154d14954f7000ed00f1727940033e45e08990b17ad492e85332fd7129c1efc666c1cd64528d86b1c6b51f33392cfe85bce
7
+ data.tar.gz: 3c33ec4701cf6b2822800ed1d474bfa1ac344554c3cdb333822ae5ddc37a173f42b5a29127918ca99a8e1a64548ef20abbc34d06d0fe222f518f8d2407d6156f
@@ -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
@@ -38,6 +41,11 @@ module ForemanAnsibleCore
38
41
  end
39
42
  end
40
43
 
44
+ def close
45
+ super
46
+ FileUtils.remove_entry(@root) if @tmp_working_dir
47
+ end
48
+
41
49
  private
42
50
 
43
51
  def handle_event_file(event_file)
@@ -79,9 +87,7 @@ module ForemanAnsibleCore
79
87
  publish_data_for(host, [header, line].join("\n"), 'stdout')
80
88
 
81
89
  # If the task has been rescued, it won't consider a failure
82
- if @exit_statuses[host].to_i != 0 && failures[host].to_i <= 0
83
- publish_exit_status_for(host, 0)
84
- end
90
+ publish_exit_status_for(host, 0) if @exit_statuses[host].to_i != 0 && failures[host].to_i <= 0
85
91
  end
86
92
  else
87
93
  broadcast_data(event['stdout'] + "\n", 'stdout')
@@ -105,7 +111,10 @@ module ForemanAnsibleCore
105
111
  end
106
112
 
107
113
  def start_ansible_runner
108
- command = ['ansible-runner', 'run', @root, '-p', 'playbook.yml']
114
+ env = {}
115
+ env['FOREMAN_CALLBACK_DISABLE'] = '1' if @rex_command
116
+ command = [env, 'ansible-runner', 'run', @root, '-p', 'playbook.yml']
117
+ command << '--cmdline' << '"--check"' if check_mode?
109
118
  command << verbosity if verbose?
110
119
  initialize_command(*command)
111
120
  logger.debug("[foreman_ansible] - Running command '#{command.join(' ')}'")
@@ -119,6 +128,10 @@ module ForemanAnsibleCore
119
128
  @verbosity_level.to_i.positive?
120
129
  end
121
130
 
131
+ def check_mode?
132
+ @check_mode == true
133
+ end
134
+
122
135
  def prepare_directory_structure
123
136
  inner = %w[inventory project].map { |part| File.join(@root, part) }
124
137
  ([@root] + inner).each do |path|
@@ -139,7 +152,12 @@ module ForemanAnsibleCore
139
152
  action_inputs = input.values.map { |hash| hash[:input][:action_input] }
140
153
  hostnames = action_inputs.map { |hash| hash[:name] }
141
154
  inventories = action_inputs.map { |hash| hash[:ansible_inventory] }
142
- host_vars = inventories.map { |i| i['_meta']['hostvars'] }.reduce(&:merge)
155
+ host_vars = inventories.map { |i| i['_meta']['hostvars'] }.reduce({}) do |acc, hosts|
156
+ hosts.reduce(acc) do |inner_acc, (hostname, vars)|
157
+ vars[:ansible_ssh_private_key_file] ||= ForemanRemoteExecutionCore.settings[:ssh_identity_key_file]
158
+ inner_acc.merge(hostname => vars)
159
+ end
160
+ end
143
161
 
144
162
  { '_meta' => { 'hostvars' => host_vars },
145
163
  'all' => { 'hosts' => hostnames,
@@ -163,8 +181,8 @@ module ForemanAnsibleCore
163
181
  per_host = secrets['per-host'][host]
164
182
 
165
183
  new_secrets = {
166
- 'ansible_ssh_pass' => inventory['ssh_password'] || per_host['ansible_ssh_pass'],
167
- 'ansible_sudo_pass' => inventory['sudo_password'] || per_host['ansible_sudo_pass']
184
+ 'ansible_password' => inventory['ssh_password'] || per_host['ansible_password'],
185
+ 'ansible_become_password' => inventory['effective_user_password'] || per_host['ansible_become_password']
168
186
  }
169
187
  inventory['_meta']['hostvars'][host].update(new_secrets)
170
188
  end
@@ -124,8 +124,8 @@ module ForemanAnsibleCore
124
124
  per_host = secrets['per-host'][name]
125
125
 
126
126
  new_secrets = {
127
- 'ansible_ssh_pass' => inventory['ssh_password'] || per_host['ansible_ssh_pass'],
128
- 'ansible_sudo_pass' => inventory['sudo_password'] || per_host['ansible_sudo_pass']
127
+ 'ansible_password' => inventory['ssh_password'] || per_host['ansible_password'],
128
+ 'ansible_become_password' => inventory['effective_user_password'] || per_host['ansible_become_password']
129
129
  }
130
130
  inventory['_meta']['hostvars'][name].update(new_secrets)
131
131
  end
@@ -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 = '3.0.5'
4
+ VERSION = '4.1.2'
5
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_ansible_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 4.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rubocop
14
+ name: foreman_remote_execution_core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.52'
20
- type: :development
19
+ version: '1.1'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.52'
26
+ version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: foreman-tasks-core
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.3.2
41
- - !ruby/object:Gem::Dependency
42
- name: foreman_remote_execution_core
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.1'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.1'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: net-ssh
57
43
  requirement: !ruby/object:Gem::Requirement