summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Teague <rteague@redhat.com>2017-08-10 22:10:08 -0400
committerGitHub <noreply@github.com>2017-08-10 22:10:08 -0400
commiteb51502b4d9794622b8dd5eeef60fc5a9f61c9e3 (patch)
treefedd7fe707a262f2fa48c794658ed1ac6c84e4d5
parent7c7b91c23cf78616df0d583a7c694b446ebef6af (diff)
parent3c7d81651b64082e8bf86a7b1398a5b621e25b49 (diff)
downloadopenshift-eb51502b4d9794622b8dd5eeef60fc5a9f61c9e3.tar.gz
openshift-eb51502b4d9794622b8dd5eeef60fc5a9f61c9e3.tar.bz2
openshift-eb51502b4d9794622b8dd5eeef60fc5a9f61c9e3.tar.xz
openshift-eb51502b4d9794622b8dd5eeef60fc5a9f61c9e3.zip
Merge pull request #5028 from mtnbikenc/entry-point-validation
More complete discovery of entry point playbooks
-rw-r--r--setup.py48
1 files changed, 32 insertions, 16 deletions
diff --git a/setup.py b/setup.py
index c6a132ae2..b9c34a8b8 100644
--- a/setup.py
+++ b/setup.py
@@ -221,27 +221,43 @@ class OpenShiftAnsibleSyntaxCheck(Command):
''' run command '''
has_errors = False
+ playbooks = set()
+ included_playbooks = set()
for yaml_file in find_files(
os.path.join(os.getcwd(), 'playbooks', 'byo'),
None, None, r'\.ya?ml$'):
with open(yaml_file, 'r') as contents:
- for line in contents:
- # initialize_groups.yml is used to identify entry point playbooks
- if re.search(r'initialize_groups\.yml', line):
- print('-' * 60)
- print('Syntax checking playbook: %s' % yaml_file)
- try:
- subprocess.check_output(
- ['ansible-playbook', '-i localhost,',
- '--syntax-check', yaml_file]
- )
- except subprocess.CalledProcessError as cpe:
- print('{}Execution failed: {}{}'.format(
- self.FAIL, cpe, self.ENDC))
- has_errors = True
- # Break for loop, no need to continue looping lines
- break
+ for task in yaml.safe_load(contents):
+ if not isinstance(task, dict):
+ # Skip yaml files which do not contain plays or includes
+ continue
+ if 'include' in task:
+ # Add the playbook and capture included playbooks
+ playbooks.add(yaml_file)
+ included_file_name = task['include'].split()[0]
+ included_file = os.path.normpath(
+ os.path.join(os.path.dirname(yaml_file),
+ included_file_name))
+ included_playbooks.add(included_file)
+ elif 'hosts' in task:
+ playbooks.add(yaml_file)
+ # Evaluate the difference between all playbooks and included playbooks
+ entrypoint_playbooks = sorted(playbooks.difference(included_playbooks))
+ print('Entry point playbook count: {}'.format(len(entrypoint_playbooks)))
+ # Syntax each entry point playbook
+ for playbook in entrypoint_playbooks:
+ print('-' * 60)
+ print('Syntax checking playbook: {}'.format(playbook))
+ try:
+ subprocess.check_output(
+ ['ansible-playbook', '-i localhost,',
+ '--syntax-check', playbook]
+ )
+ except subprocess.CalledProcessError as cpe:
+ print('{}Execution failed: {}{}'.format(
+ self.FAIL, cpe, self.ENDC))
+ has_errors = True
if has_errors:
raise SystemExit(1)