summaryrefslogtreecommitdiffstats
path: root/examples/playbooks/no_handler_pass.yml
blob: 5c448911a98c988440722defc9f127c8b8dd69d7 (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
---
- name: Fixture for no-handler-pass
  hosts: all
  tasks:
    - name: Execute something
      ansible.builtin.command: echo 123
      register: result
      changed_when: true

    - name: Print helpful error message
      ansible.builtin.debug:
        var: result
      when: result.failed

    - name: Do something when hello is output
      ansible.builtin.debug:
        msg: why isn't this a handler
      when: result.stdout == "hello"

    - name: Never actually debug
      ansible.builtin.debug:
        var: result
      when: false

    - name: "Don't execute this step"
      ansible.builtin.debug:
        msg: "debug message"
      when:
        - false

    - name: Check when with a list
      ansible.builtin.debug:
        var: result
      when:
        - conditionA
        - conditionB

    - name: Check when with a list of size 1
      ansible.builtin.debug:
        var: result
      when:
        - conditionA

    - name: Registering task 1
      ansible.builtin.command: echo Hello
      register: r1
      changed_when: true

    - name: Registering task 2
      ansible.builtin.command: echo Hello
      register: r2
      changed_when: true

    - name: Use when task # noqa: no-changed-when
      ansible.builtin.command: echo Hello
      when: r1.changed and r2.changed

    - name: Use when with or # noqa: no-changed-when
      ansible.builtin.command: echo Hello
      when: r1.changed or conditionA

    - name: Use when with list of conditions # noqa: no-changed-when
      ansible.builtin.command: echo Hello
      when:
        - r1.changed
        - conditionA

    - name: Registering task
      ansible.builtin.command: echo Hello
      register: r
      changed_when: true

    - name: When task not changed # noqa: no-changed-when
      ansible.builtin.command: echo Not changed
      when: not r.changed

    - name: Execute command # noqa: no-changed-when
      ansible.builtin.command: echo hello
      register: result

    - name: This should be a handler 2
      ansible.builtin.debug:
        msg: why isn't this a handler
      when: result | changed