| 1 |
--- |
| 2 |
- name: create helper zabbix host |
| 3 |
community.zabbix.zabbix_host: |
| 4 |
host_name: zbx_hmacro_host01 |
| 5 |
host_groups: |
| 6 |
- Linux servers |
| 7 |
interfaces: |
| 8 |
- type: agent |
| 9 |
main: 1 |
| 10 |
dns: zbx_hmacro_host01 |
| 11 |
|
| 12 |
- name: test - attempt to create new host macro |
| 13 |
community.zabbix.zabbix_hostmacro: |
| 14 |
host_name: zbx_hmacro_host01 |
| 15 |
macro_name: zbxhmacro_test01 |
| 16 |
macro_value: 123 |
| 17 |
macro_description: Global Macro description |
| 18 |
register: zbxhmacro_new |
| 19 |
|
| 20 |
- name: assert that macro was created |
| 21 |
ansible.builtin.assert: |
| 22 |
that: zbxhmacro_new is changed |
| 23 |
|
| 24 |
- name: test - attempt to create same host macro |
| 25 |
community.zabbix.zabbix_hostmacro: |
| 26 |
host_name: zbx_hmacro_host01 |
| 27 |
macro_name: zbxhmacro_test01 |
| 28 |
macro_value: 123 |
| 29 |
macro_description: Global Macro description |
| 30 |
register: zbxhmacro_existing |
| 31 |
|
| 32 |
- name: assert that nothing has been changed |
| 33 |
ansible.builtin.assert: |
| 34 |
that: not zbxhmacro_existing is changed |
| 35 |
|
| 36 |
- name: test - attempt to create same host macro in zabbix native format |
| 37 |
community.zabbix.zabbix_hostmacro: |
| 38 |
host_name: zbx_hmacro_host01 |
| 39 |
macro_name: "{$ZBXHMACRO_TEST01}" |
| 40 |
macro_value: 123 |
| 41 |
macro_description: Global Macro description |
| 42 |
register: zbxhmacro_existing_native |
| 43 |
|
| 44 |
- name: assert that nothing has been changed |
| 45 |
ansible.builtin.assert: |
| 46 |
that: not zbxhmacro_existing_native is changed |
| 47 |
|
| 48 |
- name: test - attempt to create new host macro in zabbix native format |
| 49 |
community.zabbix.zabbix_hostmacro: |
| 50 |
host_name: zbx_hmacro_host01 |
| 51 |
macro_name: "{$ZBXHMACRO_TEST02}" |
| 52 |
macro_value: abcd |
| 53 |
macro_description: Global Macro description |
| 54 |
register: zbxhmacro_new_native |
| 55 |
|
| 56 |
- name: assert that nothing macro was created |
| 57 |
ansible.builtin.assert: |
| 58 |
that: zbxhmacro_new_native is changed |
| 59 |
|
| 60 |
- name: test - attempt to update host macro with string value while force=no |
| 61 |
community.zabbix.zabbix_hostmacro: |
| 62 |
host_name: zbx_hmacro_host01 |
| 63 |
macro_name: zbxhmacro_test01 |
| 64 |
macro_value: abc |
| 65 |
macro_description: Global Macro description |
| 66 |
force: false |
| 67 |
register: zbxhmacro_update_noforce |
| 68 |
|
| 69 |
- name: assert that nothing has been changed |
| 70 |
ansible.builtin.assert: |
| 71 |
that: not zbxhmacro_update_noforce is changed |
| 72 |
|
| 73 |
- name: test - attempt to update host macro with string value |
| 74 |
community.zabbix.zabbix_hostmacro: |
| 75 |
host_name: zbx_hmacro_host01 |
| 76 |
macro_name: zbxhmacro_test01 |
| 77 |
macro_value: abc |
| 78 |
macro_description: Global Macro description |
| 79 |
register: zbxhmacro_update |
| 80 |
ignore_errors: true |
| 81 |
|
| 82 |
- name: assert that host macro was updated |
| 83 |
ansible.builtin.assert: |
| 84 |
that: zbxhmacro_update is changed |
| 85 |
|
| 86 |
- name: test - attempt to create host macro with context |
| 87 |
community.zabbix.zabbix_hostmacro: |
| 88 |
host_name: zbx_hmacro_host01 |
| 89 |
macro_name: low_space_limit:/home |
| 90 |
macro_value: 10 |
| 91 |
macro_description: Global Macro description |
| 92 |
register: zbxhmacro_context_new |
| 93 |
|
| 94 |
- name: assert that macro was created |
| 95 |
ansible.builtin.assert: |
| 96 |
that: zbxhmacro_context_new is changed |
| 97 |
|
| 98 |
- name: test - attempt to create same host macro with context and verify that it was converted to uppercase |
| 99 |
community.zabbix.zabbix_hostmacro: |
| 100 |
host_name: zbx_hmacro_host01 |
| 101 |
macro_name: LOW_SPACE_LIMIT:/home |
| 102 |
macro_value: 10 |
| 103 |
macro_description: Global Macro description |
| 104 |
register: zbxhmacro_context_existing |
| 105 |
|
| 106 |
- name: assert that nothing has been changed |
| 107 |
ansible.builtin.assert: |
| 108 |
that: not zbxhmacro_context_existing is changed |
| 109 |
|
| 110 |
- name: test - attempt to delete all host macros |
| 111 |
community.zabbix.zabbix_hostmacro: |
| 112 |
host_name: zbx_hmacro_host01 |
| 113 |
macro_name: "{{ item }}" |
| 114 |
state: absent |
| 115 |
loop: |
| 116 |
- zbxhmacro_test01 |
| 117 |
- LOW_SPACE_LIMIT:/home |
| 118 |
- "{$ZBXHMACRO_TEST02}" |
| 119 |
register: zbxhmacro_delete_existing |
| 120 |
|
| 121 |
- name: assert that all macros have been deleted |
| 122 |
ansible.builtin.assert: |
| 123 |
that: item.changed is sameas True |
| 124 |
loop: "{{ zbxhmacro_delete_existing.results }}" |
| 125 |
|
| 126 |
- name: test - attempt to delete non-existing host macro |
| 127 |
community.zabbix.zabbix_hostmacro: |
| 128 |
host_name: zbx_hmacro_host01 |
| 129 |
macro_name: zbxhmacro_test01 |
| 130 |
state: absent |
| 131 |
register: zbxhmacro_delete_missing |
| 132 |
|
| 133 |
- name: assert that nothing has been changed |
| 134 |
ansible.builtin.assert: |
| 135 |
that: not zbxhmacro_delete_missing is changed |
| 136 |
|
| 137 |
- name: test - attempt to create host macro with type secret |
| 138 |
community.zabbix.zabbix_hostmacro: |
| 139 |
host_name: zbx_hmacro_host01 |
| 140 |
macro_name: zbxhmacro_test03 |
| 141 |
macro_value: abcd |
| 142 |
macro_type: secret |
| 143 |
macro_description: Global Macro description |
| 144 |
register: zbxhmacro_update |
| 145 |
ignore_errors: true |
| 146 |
|
| 147 |
- name: assert that host macro was updated |
| 148 |
ansible.builtin.assert: |
| 149 |
that: zbxhmacro_update is changed |
| 150 |
|
| 151 |
- name: test - attempt to update host macro with type secret with same value |
| 152 |
community.zabbix.zabbix_hostmacro: |
| 153 |
host_name: zbx_hmacro_host01 |
| 154 |
macro_name: zbxhmacro_test03 |
| 155 |
macro_value: abcd |
| 156 |
macro_type: secret |
| 157 |
macro_description: Global Macro description |
| 158 |
register: zbxhmacro_update |
| 159 |
ignore_errors: true |
| 160 |
|
| 161 |
- name: assert that host macro was updated |
| 162 |
ansible.builtin.assert: |
| 163 |
that: zbxhmacro_update is changed |
| 164 |
|
| 165 |
- name: test - attempt to delete host macros type secret |
| 166 |
community.zabbix.zabbix_hostmacro: |
| 167 |
host_name: zbx_hmacro_host01 |
| 168 |
macro_name: "{{ item }}" |
| 169 |
state: absent |
| 170 |
loop: |
| 171 |
- zbxhmacro_test03 |
| 172 |
register: zbxhmacro_delete_existing |
| 173 |
|
| 174 |
- name: assert that all macros have been deleted |
| 175 |
ansible.builtin.assert: |
| 176 |
that: item.changed is sameas True |
| 177 |
loop: "{{ zbxhmacro_delete_existing.results }}" |