smart_proxy_ansible 3.4.0 → 3.5.0

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: fe91bd15ae06f9e9cc9e2d54fce101129acd7fd39f8f9c3d970909e5bf029545
4
- data.tar.gz: d6e887989f068bfa795ceada359e68d911fbeba3d308d3eb0a52e35b1571c3fd
3
+ metadata.gz: debe537cdba96e4742fc5e0311bbb073f1b25248bd5dcf394d1368f7027d2db8
4
+ data.tar.gz: 6a889c1145db1a4958f0e571d5a792e84850aa33542ba072283e95e0aa56328d
5
5
  SHA512:
6
- metadata.gz: dfc145591dd06dad090a054332802674e30f2c5b51ef22809b1dcd3a42e24f587cb4e577c9e41740ff691290fe4621610ba092c888f35eaba4fa3fa73a9f90dc
7
- data.tar.gz: 53dfb48a0c82802307cb05df916a48d146bce2505148d8eb67162ef4f87bbeab626c02ecfed46e151051d12c6af1efea7c757ac50f24768654ff39933fa2b485
6
+ metadata.gz: 02c6d84ed28a87fc0a0f18c2b5d8360e614d4c698f71a34801917157145ca499359e2cb71121d6d6fb42141dcb52a3161c13ca5ea895c8d920be3998cce141ae
7
+ data.tar.gz: ee31bc6ba19ff2a6e3d348b6f11f9c3ac25212eeb77c6dad32556c49af254cec5320603a63c3c1dea28282561e1fc136e896f4a3f8b3b3db96ae001cc4cd50ae
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ [ -f "$SMART_PROXY_ANSIBLE_ENVIRONMENT_FILE" ] && source "$SMART_PROXY_ANSIBLE_ENVIRONMENT_FILE"
4
+ exec "$@"
@@ -5,7 +5,8 @@ module Proxy
5
5
  rackup_path File.expand_path('http_config.ru', __dir__)
6
6
  settings_file 'ansible.yml'
7
7
  plugin :ansible, Proxy::Ansible::VERSION
8
- default_settings :ansible_dir => Dir.home
8
+ default_settings :ansible_dir => Dir.home,
9
+ :ansible_environment_file => '/etc/foreman-proxy/ansible.env'
9
10
  # :working_dir => nil
10
11
 
11
12
  load_classes ::Proxy::Ansible::ConfigurationLoader
@@ -10,6 +10,9 @@ module Proxy::Ansible
10
10
  include ::Proxy::Dynflow::Runner::ProcessManagerCommand
11
11
  attr_reader :execution_timeout_interval
12
12
 
13
+ # To make this overridable in development
14
+ ENVIRONMENT_WRAPPER = ENV['SMART_PROXY_ANSIBLE_ENVIRONMENT_WRAPPER'] || '/usr/libexec/foreman-proxy/ansible-runner-environment'
15
+
13
16
  def initialize(input, suspended_action:, id: nil)
14
17
  super input, :suspended_action => suspended_action, :id => id
15
18
  @inventory = rebuild_secrets(rebuild_inventory(input), input)
@@ -65,6 +68,7 @@ module Proxy::Ansible
65
68
  def publish_exit_status(status)
66
69
  process_artifacts
67
70
  super
71
+ @targets.each_key { |host| publish_exit_status_for(host, status) } if status != 0
68
72
  end
69
73
 
70
74
  def initialize_command(*command)
@@ -98,7 +102,7 @@ module Proxy::Ansible
98
102
  logger.debug("[foreman_ansible] - parsing event file #{event_file}")
99
103
  begin
100
104
  event = JSON.parse(File.read(event_file))
101
- if (hostname = event.dig('event_data', 'host'))
105
+ if (hostname = hostname_for_event(event))
102
106
  handle_host_event(hostname, event)
103
107
  else
104
108
  handle_broadcast_data(event)
@@ -110,6 +114,17 @@ module Proxy::Ansible
110
114
  end
111
115
  end
112
116
 
117
+ def hostname_for_event(event)
118
+ hostname = event.dig('event_data', 'host') || event.dig('event_data', 'remote_addr')
119
+ return nil if hostname.nil? || hostname.empty?
120
+
121
+ unless @targets.key?(hostname)
122
+ logger.warn("handle_host_event: unknown host #{hostname} for event '#{event['event']}', broadcasting")
123
+ return nil
124
+ end
125
+ hostname
126
+ end
127
+
113
128
  def handle_host_event(hostname, event)
114
129
  log_event("for host: #{hostname.inspect}", event)
115
130
  publish_data_for(hostname, event['stdout'] + "\n", 'stdout') if event['stdout']
@@ -175,10 +190,12 @@ module Proxy::Ansible
175
190
  def start_ansible_runner
176
191
  env = {}
177
192
  env['FOREMAN_CALLBACK_DISABLE'] = '1' if @rex_command
178
- command = [env, 'ansible-runner', 'run', @root, '-p', 'playbook.yml']
193
+ env['SMART_PROXY_ANSIBLE_ENVIRONMENT_FILE'] = Proxy::Ansible::Plugin.settings[:ansible_environment_file]
194
+ command = ['ansible-runner', 'run', @root, '-p', 'playbook.yml']
179
195
  command << '--cmdline' << cmdline unless cmdline.nil?
180
196
  command << verbosity if verbose?
181
- initialize_command(*command)
197
+
198
+ initialize_command(env, ENVIRONMENT_WRAPPER, *command)
182
199
  logger.debug("[foreman_ansible] - Running command '#{command.join(' ')}'")
183
200
  end
184
201
 
@@ -2,6 +2,6 @@ module Proxy
2
2
  # Version, this allows the proxy and other plugins know
3
3
  # what version of the Ansible plugin is running
4
4
  module Ansible
5
- VERSION = '3.4.0'
5
+ VERSION = '3.5.0'
6
6
  end
7
7
  end
@@ -1,3 +1,4 @@
1
1
  ---
2
2
  :enabled: true
3
3
  :working_dir: '~/.foreman-ansible'
4
+ # :ansible_environment_file: /etc/foreman-proxy/ansible.env
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 1980-01-01 00:00:00.000000000 Z
12
+ date: 2022-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -149,6 +149,7 @@ extra_rdoc_files:
149
149
  files:
150
150
  - LICENSE
151
151
  - README.md
152
+ - bin/ansible-runner-environment.sh
152
153
  - bin/json_inventory.sh
153
154
  - bundler.d/ansible.rb
154
155
  - lib/smart_proxy_ansible.rb
@@ -185,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
186
  - !ruby/object:Gem::Version
186
187
  version: '0'
187
188
  requirements: []
188
- rubygems_version: 3.2.26
189
+ rubygems_version: 3.3.20
189
190
  signing_key:
190
191
  specification_version: 4
191
192
  summary: Smart-Proxy Ansible plugin