Check jinja templates for syntax error (#10667)
Allow to fail early (pre-commit time) for jinja error, rather than waiting until executing the playbook and the invalid template. I could not find a simple jinja pre-commit hook in the wild.pull/10694/head
parent
fe02d21d23
commit
d2944d2813
|
@ -27,6 +27,14 @@ ansible-lint:
|
||||||
- ansible-lint -v
|
- ansible-lint -v
|
||||||
except: ['triggers', 'master']
|
except: ['triggers', 'master']
|
||||||
|
|
||||||
|
jinja-syntax-check:
|
||||||
|
extends: .job
|
||||||
|
stage: unit-tests
|
||||||
|
tags: [light]
|
||||||
|
script:
|
||||||
|
- "find -name '*.j2' -exec tests/scripts/check-templates.py {} +"
|
||||||
|
except: ['triggers', 'master']
|
||||||
|
|
||||||
syntax-check:
|
syntax-check:
|
||||||
extends: .job
|
extends: .job
|
||||||
stage: unit-tests
|
stage: unit-tests
|
||||||
|
|
|
@ -69,3 +69,12 @@ repos:
|
||||||
entry: tests/scripts/md-table/test.sh
|
entry: tests/scripts/md-table/test.sh
|
||||||
language: script
|
language: script
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
|
|
||||||
|
- id: jinja-syntax-check
|
||||||
|
name: jinja-syntax-check
|
||||||
|
entry: tests/scripts/check-templates.py
|
||||||
|
language: python
|
||||||
|
types:
|
||||||
|
- jinja
|
||||||
|
additional_dependencies:
|
||||||
|
- Jinja2
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from jinja2 import Environment
|
||||||
|
|
||||||
|
env = Environment()
|
||||||
|
for template in sys.argv[1:]:
|
||||||
|
with open(template) as t:
|
||||||
|
env.parse(t.read())
|
Loading…
Reference in New Issue