summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Henkel <tobias.henkel@bmw.de>2019-02-17 08:48:18 +0100
committerTobias Henkel <tobias.henkel@bmw.de>2019-03-15 09:09:16 +0100
commit07ab212f014002b375c279949f3414f04847d8c7 (patch)
tree41207410d29001a1a41954bdde7a196a80738aac
parentcd9827e6649b7f14513c2f201afc9e9d46998ddb (diff)
downloadzuul-07ab212f014002b375c279949f3414f04847d8c7.tar.gz
Validate ansible installations on startup
Instead of failing jobs when trying to use non-existing ansible installations it should validate if all supported ansible installations are available during startup. Change-Id: Ida05001634938f5b3a6c191cf2c750e788f3ccbb
-rw-r--r--zuul/executor/server.py6
-rw-r--r--zuul/lib/ansible.py23
2 files changed, 29 insertions, 0 deletions
diff --git a/zuul/executor/server.py b/zuul/executor/server.py
index b3bf0119f..46459e784 100644
--- a/zuul/executor/server.py
+++ b/zuul/executor/server.py
@@ -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):
diff --git a/zuul/lib/ansible.py b/zuul/lib/ansible.py
index 83c0afe04..ca5aa7b93 100644
--- a/zuul/lib/ansible.py
+++ b/zuul/lib/ansible.py
@@ -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