summaryrefslogtreecommitdiffstats
path: root/setup.py
diff options
context:
space:
mode:
authorRussell Teague <rteague@redhat.com>2017-08-08 11:10:03 -0400
committerRussell Teague <rteague@redhat.com>2017-08-08 15:20:16 -0400
commit3c7d81651b64082e8bf86a7b1398a5b621e25b49 (patch)
treecf6ebd2bf98f4b64781edc24cd502a92070b1902 /setup.py
parent0569c5069dabeea9e2fe94cd097cb6f2b1540867 (diff)
downloadopenshift-3c7d81651b64082e8bf86a7b1398a5b621e25b49.tar.gz
openshift-3c7d81651b64082e8bf86a7b1398a5b621e25b49.tar.bz2
openshift-3c7d81651b64082e8bf86a7b1398a5b621e25b49.tar.xz
openshift-3c7d81651b64082e8bf86a7b1398a5b621e25b49.zip
More complete discovery of entry point playbooks
This change scans for supported entry point playbooks based on the following conditions: * In the supported directory of playbooks/byo * Playbooks not included by any other playbooks
Diffstat (limited to 'setup.py')
-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)