@@ -4,7 +4,14 @@ class << self
4
4
def available?
5
5
return @available if defined? ( @available )
6
6
7
- @available = system ( "which ansible-runner >/dev/null 2>&1" )
7
+ @available = system ( runner_env , "which ansible-runner >/dev/null 2>&1" )
8
+ end
9
+
10
+ def runner_env
11
+ @runner_env ||= {
12
+ "PYTHONPATH" => [ venv_python_path , ansible_python_path ] . compact . join ( File ::PATH_SEPARATOR ) ,
13
+ "PATH" => [ venv_bin_path , ENV [ "PATH" ] . presence ] . compact . join ( File ::PATH_SEPARATOR )
14
+ } . delete_blanks
8
15
end
9
16
10
17
# Runs a playbook via ansible-runner, see: https://ansible-runner.readthedocs.io/en/latest/standalone.html#running-playbooks
@@ -221,6 +228,8 @@ def run_via_cli(hosts, credentials, env_vars, extra_vars, tags: nil, ansible_run
221
228
222
229
params = runner_params ( base_dir , ansible_runner_method , playbook_or_role_args , verbosity )
223
230
231
+ # puts "#{env_vars_hash.map { |k, v| "#{k}=#{v}" }.join(" ")} #{AwesomeSpawn.build_command_line("ansible-runner", params)}"
232
+
224
233
begin
225
234
fetch_galaxy_roles ( playbook_or_role_args )
226
235
@@ -317,11 +326,7 @@ def fetch_galaxy_roles(playbook_or_role_args)
317
326
return unless playbook_or_role_args [ :playbook ]
318
327
319
328
playbook_dir = File . dirname ( playbook_or_role_args [ :playbook ] )
320
- Ansible ::Content . new ( playbook_dir ) . fetch_galaxy_roles
321
- end
322
-
323
- def runner_env
324
- { "PYTHONPATH" => python_path } . delete_nils
329
+ Ansible ::Content . new ( playbook_dir ) . fetch_galaxy_roles ( runner_env )
325
330
end
326
331
327
332
def credentials_info ( credentials , base_dir )
@@ -408,34 +413,42 @@ def wait_for_listener_start(listener)
408
413
end
409
414
end
410
415
411
- def python_path
412
- @python_path ||= [ manageiq_venv_path , *ansible_python_paths ] . compact . join ( File ::PATH_SEPARATOR )
416
+ VENV_ROOT = "/var/lib/manageiq/venv" . freeze
417
+
418
+ def venv_python_path
419
+ return @venv_python_path if defined? ( @venv_python_path )
420
+
421
+ @venv_python_path = Dir . glob ( File . join ( VENV_ROOT , "lib/python#{ ansible_python_version } /site-packages" ) ) . first
413
422
end
414
423
415
- def manageiq_venv_path
416
- Dir . glob ( "/var/lib/manageiq/venv/lib/python*/site-packages" ) . first
424
+ def venv_bin_path
425
+ return @venv_bin_path if defined? ( @venv_bin_path )
426
+
427
+ @venv_bin_path = Dir . glob ( File . join ( VENV_ROOT , "bin" ) ) . first
428
+ end
429
+
430
+ def ansible_python_path
431
+ python_path_raw ( ansible_python_version ) . presence
417
432
end
418
433
419
- def ansible_python_paths
420
- ansible_python_paths_raw ( ansible_python_version ) . chomp . split ( ":" )
434
+ def ansible_python_version
435
+ ansible_version_raw . match ( /python version = ( \d + \. \d +) \. / ) &. captures &. first
421
436
end
422
437
423
438
# NOTE: This method is ignored by brakeman in the config/brakeman.ignore
424
- def ansible_python_paths_raw ( version )
439
+ def python_path_raw ( version )
425
440
return "" if version . blank?
426
441
427
442
# This check allows us to ignore the brakeman warning about command line injection
428
- raise "ansible python version is not a number: #{ version } " unless version . match? ( /^\d +\. \d +$/ )
443
+ raise "python version is not a number: #{ version } " unless version . match? ( /^\d +\. \d +$/ )
429
444
430
445
`python#{ version } -c 'import site; print(":".join(site.getsitepackages()))'` . chomp
431
446
end
432
447
433
- def ansible_python_version
434
- ansible_python_version_raw . match ( /python version = (\d +\. \d +)\. / ) &.captures &.first
435
- end
436
-
437
- def ansible_python_version_raw
438
- `ansible --version 2>/dev/null` . chomp
448
+ # NOTE: This method is ignored by brakeman in the config/brakeman.ignore
449
+ def ansible_version_raw
450
+ ansible = venv_bin_path ? File . join ( venv_bin_path , "ansible" ) : "ansible"
451
+ `#{ ansible } --version 2>/dev/null` . chomp
439
452
end
440
453
end
441
454
end
0 commit comments