foreman_ansible_core 3.0.4 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b9ed358d85932fcb1710bc33ff885319f5478daa58083520749a99a2af67626
4
- data.tar.gz: 9efdcf103ab555abb5ea60d1e8e757110a514d73a4dfa00bcd1f5cef68c81e0b
3
+ metadata.gz: 278c99763d5ca8b32972c482295e69eeb169361d9672676698f8e86b9fd7b280
4
+ data.tar.gz: 9685147c5aceff5a56228a6a1cb62bd68d3c70f8a86d8abf53c1a5d93c514ada
5
5
  SHA512:
6
- metadata.gz: b1ab98aeae41f8232d6eef1d3057e332eae7c7716768f54862b259dd7aae4236c20a0b628e8164336fcdb9d30d7ff29387f3f72eb118dd6faa55a92a745c44fe
7
- data.tar.gz: 0e1fc4865413fc4d5be78ad7a5e5b7741103aa22618cd419d2b52ed584042588faac547427bdc46447c5fcb354b1015b704e71e75123ff89a0cdcc2daa99785c
6
+ metadata.gz: ff78d8748767c661088e575b1085090e0d6f4c863422dd7facb00c26dc1bbc1b38afc81b3f39a0817a27ee1108db6efde79cd339176d18db18612dc08af3972a
7
+ data.tar.gz: 639a28fa06bce26cee23f746aed5192d7b909b81680b4186a4180d73f570742424e71bcaefa64e52db3405534604c339df2cf38d3c87fdd60b5eeb848811216c
@@ -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)
@@ -72,10 +80,16 @@ module ForemanAnsibleCore
72
80
  def handle_broadcast_data(event)
73
81
  log_event("broadcast", event)
74
82
  if event['event'] == 'playbook_on_stats'
83
+ failures = event.dig('event_data', 'failures') || {}
75
84
  header, *rows = event['stdout'].strip.lines.map(&:chomp)
76
85
  @outputs.keys.select { |key| key.is_a? String }.each do |host|
77
86
  line = rows.find { |row| row =~ /#{host}/ }
78
87
  publish_data_for(host, [header, line].join("\n"), 'stdout')
88
+
89
+ # If the task has been rescued, it won't consider a failure
90
+ if @exit_statuses[host].to_i != 0 && failures[host].to_i <= 0
91
+ publish_exit_status_for(host, 0)
92
+ end
79
93
  end
80
94
  else
81
95
  broadcast_data(event['stdout'] + "\n", 'stdout')
@@ -99,7 +113,10 @@ module ForemanAnsibleCore
99
113
  end
100
114
 
101
115
  def start_ansible_runner
102
- command = ['ansible-runner', 'run', @root, '-p', 'playbook.yml']
116
+ env = {}
117
+ env['FOREMAN_CALLBACK_DISABLE'] = '1' if @rex_command
118
+ command = [env, 'ansible-runner', 'run', @root, '-p', 'playbook.yml']
119
+ command << '--cmdline' << '"--check"' if check_mode?
103
120
  command << verbosity if verbose?
104
121
  initialize_command(*command)
105
122
  logger.debug("[foreman_ansible] - Running command '#{command.join(' ')}'")
@@ -113,6 +130,10 @@ module ForemanAnsibleCore
113
130
  @verbosity_level.to_i.positive?
114
131
  end
115
132
 
133
+ def check_mode?
134
+ @check_mode == true
135
+ end
136
+
116
137
  def prepare_directory_structure
117
138
  inner = %w[inventory project].map { |part| File.join(@root, part) }
118
139
  ([@root] + inner).each do |path|
@@ -133,7 +154,12 @@ module ForemanAnsibleCore
133
154
  action_inputs = input.values.map { |hash| hash[:input][:action_input] }
134
155
  hostnames = action_inputs.map { |hash| hash[:name] }
135
156
  inventories = action_inputs.map { |hash| hash[:ansible_inventory] }
136
- host_vars = inventories.map { |i| i['_meta']['hostvars'] }.reduce(&:merge)
157
+ host_vars = inventories.map { |i| i['_meta']['hostvars'] }.reduce({}) do |acc, hosts|
158
+ hosts.reduce(acc) do |inner_acc, (hostname, vars)|
159
+ vars[:ansible_ssh_private_key_file] ||= ForemanRemoteExecutionCore.settings[:ssh_identity_key_file]
160
+ inner_acc.merge(hostname => vars)
161
+ end
162
+ end
137
163
 
138
164
  { '_meta' => { 'hostvars' => host_vars },
139
165
  'all' => { 'hosts' => hostnames,
@@ -157,8 +183,8 @@ module ForemanAnsibleCore
157
183
  per_host = secrets['per-host'][host]
158
184
 
159
185
  new_secrets = {
160
- 'ansible_ssh_pass' => inventory['ssh_password'] || per_host['ansible_ssh_pass'],
161
- 'ansible_sudo_pass' => inventory['sudo_password'] || per_host['ansible_sudo_pass']
186
+ 'ansible_password' => inventory['ssh_password'] || per_host['ansible_password'],
187
+ 'ansible_become_password' => inventory['effective_user_password'] || per_host['ansible_become_password']
162
188
  }
163
189
  inventory['_meta']['hostvars'][host].update(new_secrets)
164
190
  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' => input['action_input'].slice('name') }
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.4'
4
+ VERSION = '4.1.1'
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.4
4
+ version: 4.1.1
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-09-22 00:00:00.000000000 Z
11
+ date: 2021-07-20 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
@@ -91,7 +77,7 @@ homepage: https://github.com/theforeman/foreman_ansible
91
77
  licenses:
92
78
  - GPL-3.0
93
79
  metadata: {}
94
- post_install_message:
80
+ post_install_message:
95
81
  rdoc_options: []
96
82
  require_paths:
97
83
  - lib
@@ -106,8 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
92
  - !ruby/object:Gem::Version
107
93
  version: '0'
108
94
  requirements: []
109
- rubygems_version: 3.0.3
110
- signing_key:
95
+ rubygems_version: 3.1.2
96
+ signing_key:
111
97
  specification_version: 4
112
98
  summary: 'Ansible integration with Foreman (theforeman.org): core bits'
113
99
  test_files: []