Prepend path with bin dir of ansible virtualenv

Tools like ara are now installed within the virtualenv where ansible
is installed. We need to add the bindir of those into the path so
ansible will find them.

Change-Id: Ic8d0cf821222f792e892a765b2dccaa0f35653af
changes/27/649427/1
Tobias Henkel 4 years ago
parent 63976c5815
commit 70ec13a7ca
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2

@ -0,0 +1,4 @@
- hosts: localhost
tasks:
- name: Run ara
shell: ara --help

@ -0,0 +1,27 @@
- pipeline:
name: check
manager: independent
post-review: true
trigger:
gerrit:
- event: patchset-created
success:
gerrit:
Verified: 1
failure:
gerrit:
Verified: -1
- job:
name: base
parent: null
- job:
name: test-ara
run: playbooks/ara.yaml
- project:
name: org/project
check:
jobs:
- test-ara

@ -0,0 +1,8 @@
- tenant:
name: tenant-one
source:
gerrit:
config-projects:
- common-config
untrusted-projects:
- org/project

@ -5719,3 +5719,20 @@ class TestDefaultAnsibleVersion(AnsibleZuulTestCase):
dict(name='ansible-26', result='SUCCESS', changes='1,1'),
dict(name='ansible-27', result='SUCCESS', changes='1,1'),
], ordered=False)
class TestAraInPath(AnsibleZuulTestCase):
tenant_config_file = 'config/ara-in-path/main.yaml'
def test_ara_in_path(self):
"""
Tests that executables like ara are in the path of the virtualenv.
"""
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertHistory([
dict(name='test-ara', result='SUCCESS', changes='1,1'),
])

@ -1857,6 +1857,13 @@ class AnsibleJob(object):
pythonpath = [ansible_dir] + pythonpath
env_copy['PYTHONPATH'] = os.path.pathsep.join(pythonpath)
# Prepend PATH with ansible_dir/bin so tools installed into the venv
# can be called in local tasks.
env_copy['PATH'] = '{}{}{}'.format(
os.path.dirname(cmd[0]),
os.path.pathsep,
env_copy['PATH'])
if playbook.trusted:
opt_prefix = 'trusted'
else:

Loading…
Cancel
Save