-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call ansible-playbook for each playbook using --syntax-check. Dummy roles and inventory is provided to avoid false error detection. The python script also format the error output to be compliant to github pipeline standard. Add Github pipeline to run this test.
- Loading branch information
Showing
7 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
- hosts: hana | ||
remote_user: cloudadmin | ||
become: true | ||
xbecome: true | ||
become_user: root | ||
|
||
pre_tasks: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import subprocess | ||
import re | ||
import sys | ||
import os | ||
|
||
def syntax_check_playbook(path): | ||
cmd = ['ansible-playbook', '-i', 'tools/inventory.yaml', '-l', 'all', '--syntax-check', path] | ||
proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=False) | ||
output = proc.stdout.decode('utf-8') | ||
if proc.returncode == 0: | ||
return output, [] | ||
|
||
errors = [] | ||
match = re.search(r".*ERROR!(.*)\n+The error.*in '(.*)'.*line (\d+)", output, re.MULTILINE) | ||
if match: | ||
errors.append({ | ||
'file': match.group(2), | ||
'line': int(match.group(3)), | ||
'message': match.group(1).strip() | ||
}) | ||
return output, errors | ||
|
||
if __name__ == '__main__': | ||
playbooks_folder = 'ansible/playbooks' | ||
# Iterate directory | ||
has_error = False | ||
for path in os.listdir(playbooks_folder): | ||
playbook = os.path.join(playbooks_folder, path) | ||
# check if current path is a file | ||
if not os.path.isfile(playbook): | ||
continue | ||
output, errors = syntax_check_playbook(playbook) | ||
if len(errors) > 0: | ||
if "GITHUB_ACTIONS" in os.environ: | ||
for error in errors: | ||
print('::error file={},line={},endLine={},title=ERROR::{}'.format( | ||
error['file'], error['line'], error['line'], error['message'] | ||
)) | ||
else: | ||
print(output) | ||
has_error = True | ||
|
||
if has_error: | ||
sys.exit(1) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
all: | ||
vars: | ||
use_sbd: true | ||
resource_group_name: rg-name | ||
subscription_id: AAAAA-BBBBB-CCCCC-DDDDD | ||
tenant_id: EEEEE-FFFFF-GGGGG-HHHHH | ||
cluster_ip: 1.2.3.4 | ||
children: | ||
hana: | ||
hosts: | ||
vmhana01: | ||
ansible_host: 1.2.3.4 | ||
ansible_python_interpreter: /usr/bin/python3 | ||
vmhana02: | ||
ansible_host: 5.6.7.8 | ||
ansible_python_interpreter: /usr/bin/python3 | ||
|
||
iscsi: | ||
hosts: | ||
vmiscsi01: | ||
ansible_host: 9.9.9.9 | ||
ansible_python_interpreter: /usr/bin/python3 | ||
|
||
hosts: null |