summaryrefslogtreecommitdiffstats
path: root/examples/playbooks/jinja-spacing.yml
blob: b6824c28a8f4562d570d3674b700a1a2e09f9b13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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)}}