summaryrefslogtreecommitdiffstats
path: root/examples/playbooks/jinja-spacing.yml
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:06:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:06:49 +0000
commit2fe34b6444502079dc0b84365ce82dbc92de308e (patch)
tree8fedcab52bbbc3db6c5aa909a88a7a7b81685018 /examples/playbooks/jinja-spacing.yml
parentInitial commit. (diff)
downloadansible-lint-upstream/6.17.2.tar.xz
ansible-lint-upstream/6.17.2.zip
Adding upstream version 6.17.2.upstream/6.17.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/playbooks/jinja-spacing.yml')
-rw-r--r--examples/playbooks/jinja-spacing.yml89
1 files changed, 89 insertions, 0 deletions
diff --git a/examples/playbooks/jinja-spacing.yml b/examples/playbooks/jinja-spacing.yml
new file mode 100644
index 0000000..b6824c2
--- /dev/null
+++ b/examples/playbooks/jinja-spacing.yml
@@ -0,0 +1,89 @@
+---
+# Should raise jinja[spacing] at tasks line 23, 26, 29, 54, 65
+- name: Fixture for testing jinja2[spacing]
+ hosts: all
+ tasks:
+ - name: Good variable format
+ ansible.builtin.debug:
+ msg: "{{ good_format }}"
+ - name: Good variable format
+ ansible.builtin.debug:
+ msg: "Value: {{ good_format }}"
+ - name: Good variable filter format
+ ansible.builtin.debug:
+ msg: "{{ good_format | filter }}"
+ - name: Good variable filter format
+ ansible.builtin.debug:
+ msg: "Value: {{ good_format | filter }}"
+ - name: Jinja escaping allowed
+ ansible.builtin.debug:
+ msg: "{{ '{{' }}"
+ - name: Jinja escaping allowed
+ # noqa: risky-shell-pipe
+ ansible.builtin.shell: docker info --format '{{ '{{' }}json .Swarm.LocalNodeState{{ '}}' }}' | tr -d '"'
+ changed_when: false
+ - name: Jinja whitespace control allowed
+ ansible.builtin.debug:
+ msg: |
+ {{ good_format }}/
+ {{- good_format }}
+ {{- good_format -}}
+ - name: Bad variable format
+ ansible.builtin.debug:
+ msg: "{{bad_format}}" # <-- 1
+ - name: Bad variable format
+ ansible.builtin.debug:
+ msg: "Value: {{ bad_format}}" # <-- 2
+ - name: Bad variable format
+ ansible.builtin.debug:
+ msg: "{{bad_format }}" # <-- 3
+ - name: Bad variable filter format
+ ansible.builtin.debug:
+ msg: "{{ bad_format|filter }}" # <-- 4
+ - name: Bad variable filter format
+ ansible.builtin.debug:
+ msg: "Value: {{ bad_format |filter }}" # <-- 5
+ - name: Bad variable filter format
+ ansible.builtin.debug:
+ msg: "{{ bad_format| filter }}" # <-- 6
+ - name: Not a jinja variable # noqa: jinja[spacing]
+ ansible.builtin.debug:
+ # spell-checker: disable-next-line
+ msg: data = ${lookup{$local_part}lsearch{/etc/aliases}}
+ - name: JSON inside jinja is valid
+ ansible.builtin.debug:
+ msg: "{{ {'test': {'subtest': variable}} }}"
+ - name: Avoid false positive on multiline
+ vars:
+ cases:
+ case1: >-
+ http://foo.com/{{
+ case1 }}
+ case2: >-
+ http://bar.com/{{
+ case2 }}
+ ansible.builtin.debug:
+ var: cases
+
+ - name: Valid single line nested JSON false positive
+ ansible.builtin.debug:
+ msg: "{{ {'dummy_2': {'nested_dummy_1': 'value_1', 'nested_dummy_2': value_2}} | combine(dummy_1) }}"
+
+ - name: Invalid single line nested JSON
+ ansible.builtin.debug:
+ msg: "{{ {'dummy_2': {'nested_dummy_1': 'value_1', 'nested_dummy_2': value_2}} | combine(dummy_1)}}" # <-- 7
+
+ - name: Valid multiline nested JSON false positive
+ ansible.builtin.debug:
+ msg: >-
+ {{ {'dummy_2': {'nested_dummy_1': value_1,
+ 'nested_dummy_2': value_2}} |
+ combine(dummy_1) }}
+
+ - name: Invalid multiline nested JSON
+ ansible.builtin.debug:
+ # not an error currently because current implementation skips multiline expressions
+ msg: >-
+ {{ {'dummy_2': {'nested_dummy_1': value_1,
+ 'nested_dummy_2': value_2}} |
+ combine(dummy_1)}}