Debian Codegraph @

src/ansiblelint/rules/jinja_template_extension.md

raw symbols SCIP
1 # jinja-template-extension
2
3 This rule checks that files used with `ansible.builtin.template` have a
4 `.j2` extension.
5
6 Naming template source files with a `.j2` suffix provides several benefits:
7
8 - **Editor support**: Editors can apply Jinja2 syntax highlighting
9 automatically based on the file extension.
10 - **Clear intent**: Developers can immediately distinguish template files
11 from static files in the `templates/` directory.
12 - **Convention**: The `.j2` extension is the widely adopted community
13 convention for Ansible template files.
14
15 This is an opt-in rule.
16 You must enable it in your Ansible-lint configuration as follows:
17
18 ```yaml
19 enable_list:
20 - jinja-template-extension
21 ```
22
23 ## Problematic Code
24
25 ```yaml
26 ---
27 - name: Example playbook
28 hosts: all
29 tasks:
30 - name: Deploy config
31 ansible.builtin.template:
32 src: httpd.conf # <- Missing .j2 extension.
33 dest: /etc/httpd/conf/httpd.conf
34 mode: "0644"
35 ```
36
37 ## Correct Code
38
39 ```yaml
40 ---
41 - name: Example playbook
42 hosts: all
43 tasks:
44 - name: Deploy config
45 ansible.builtin.template:
46 src: httpd.conf.j2 # <- Proper .j2 extension.
47 dest: /etc/httpd/conf/httpd.conf
48 mode: "0644"
49 ```