summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/handlers/test_handlers_listen.yml
blob: dd2cd87dd9a506b6b088c3d6cffd45dc5fb5f300 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
- name: test listen with named handlers
  hosts: localhost
  gather_facts: false
  tasks:
    - name: test notify handlers listen
      command: uptime
      notify:
        - notify_listen
    - meta: flush_handlers
    - name: verify test notify handlers listen
      assert:
        that:
          - "notify_listen_ran_1_1 is defined"
          - "notify_listen_ran_1_2 is defined"
          - "notify_listen_ran_1_3 is undefined"
  handlers:
    - name: notify_handler_ran_1_1
      set_fact:
        notify_listen_ran_1_1: True
      listen: notify_listen
    - name: notify_handler_ran_1_2
      set_fact:
        notify_listen_ran_1_2: True
      listen: notify_listen
    - name: notify_handler_ran_1_3
      set_fact:
        notify_handler_ran_1_3: True
      listen: notify_listen2

- name: test listen unnamed handlers
  hosts: localhost
  gather_facts: false
  pre_tasks:
    - name: notify some handlers
      command: echo foo
      notify:
        - notify_listen
  tasks:
    - meta: flush_handlers
    - name: assert all defined handlers ran without error
      assert:
        that:
          - "notify_listen_ran_1 is defined"
          - "notify_listen_ran_2 is defined"
          - "notify_listen_ran_3 is undefined"
  handlers:
    - set_fact:
        notify_listen_ran_1: True
      listen: notify_listen
    - set_fact:
        notify_listen_ran_2: True
      listen: notify_listen
    - set_fact:
        notify_handler_ran_3: True
      listen: notify_listen2

- name: test with mixed notify by name and listen
  hosts: localhost
  gather_facts: false
  tasks:
    - name: test notify handlers names and identical listen
      command: uptime
      notify:
        - notify_listen
    - meta: flush_handlers
    - name: verify test notify handlers names and identical listen
      assert:
        that:
          - "notify_handler_name_ran_3 is defined"
          - "notify_handler_name_ran_3_1 is not defined"
          - "notify_listen_ran_3_2 is defined"
          - "notify_listen_ran_3_3 is defined"
          - "not_notify_listen_3_4 is not defined"
  handlers:
    - name: notify_listen
      set_fact:
        notify_handler_name_ran_3: True
    # this will not run as we have a handler with a identical name notified first
    - name: notify_listen
      set_fact:
        notify_handler_name_ran_3_1: True
    - name: notify_handler_ran_3_2
      set_fact:
        notify_listen_ran_3_2: True
      listen: notify_listen
    - name: notify_handler_ran_3_3
      set_fact:
        notify_listen_ran_3_3: True
      listen: notify_listen
    # this one is not notified
    - name: not_notify_listen_3_4
      set_fact:
        not_notify_listen_3_4: True
      listen: not_notified

- name: test listen in roles
  hosts: localhost
  gather_facts: false
  roles:
    - role: test_handlers_listen
  tasks:
    - name: test notify handlers listen in roles
      command: uptime
      notify:
        - notify_listen
    - meta: flush_handlers
    - name: verify test notify handlers listen in roles
      assert:
        that:
          - "notify_listen_ran_4_1 is defined"
          - "notify_listen_ran_4_2 is defined"
          - "notify_listen_ran_4_3 is defined"
          - "notify_listen_in_role_4 is defined"
          - "notify_listen_from_role_4 is defined"
  handlers:
    - name: notify_listen_ran_4_1
      set_fact:
        notify_listen_ran_4_1: True
      listen: notify_listen
    - name: notify_listen_ran_4_2
      set_fact:
        notify_listen_ran_4_2: True
      listen: notify_listen
    - name: notify_listen_from_role_4
      set_fact:
        notify_listen_from_role_4: True
      listen: notify_listen_from_role