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
This commit is contained in:
Tobias Henkel 2019-04-02 20:46:54 +02:00
parent 63976c5815
commit 70ec13a7ca
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
6 changed files with 64 additions and 0 deletions

View File

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

View File

@ -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

View File

@ -0,0 +1 @@
test

View File

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

View File

@ -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'),
])

View File

@ -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: