Merge "Validate ansible installations on startup"

This commit is contained in:
Zuul 2019-03-18 07:16:36 +00:00 committed by Gerrit Code Review
commit 9b95c91f31
2 changed files with 29 additions and 0 deletions

View File

@ -2279,6 +2279,12 @@ class ExecutorServer(object):
ansible_dir = os.path.join(state_dir, 'ansible')
self.ansible_manager = AnsibleManager(ansible_dir)
if not self.ansible_manager.validate():
# TODO(tobiash): Install ansible here if auto install on startup is
# requested
raise Exception('Error while validating ansible installations. '
'Please run zuul-manage-ansible to install all '
'supported ansible versions.')
self.ansible_manager.copyAnsibleFiles()
def _getMerger(self, root, cache_root, logger=None):

View File

@ -161,6 +161,29 @@ class AnsibleManager:
for future in concurrent.futures.as_completed(futures):
future.result()
def validate(self):
result = True
for version in self._supported_versions:
command = [
self.getAnsibleCommand(version, 'ansible'),
'--version',
]
try:
result = subprocess.run(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True)
self.log.info('Ansible version %s information: \n%s',
version, result.stdout.decode())
except FileNotFoundError:
result = False
self.log.exception('Ansible version %s not found' % version)
except subprocess.CalledProcessError:
result = False
self.log.exception("Ansible version %s not working" % version)
return result
def _getAnsible(self, version):
if not version:
version = self.default_version