| 1 |
--- |
| 2 |
- name: Create FTP Service Template |
| 3 |
community.zabbix.zabbix_template: |
| 4 |
template_name: FTP Service |
| 5 |
template_groups: |
| 6 |
- "Templates" |
| 7 |
state: present |
| 8 |
|
| 9 |
- name: Create a new Zabbix template (check mode). |
| 10 |
community.zabbix.zabbix_template: |
| 11 |
template_name: ExampleHost |
| 12 |
template_groups: |
| 13 |
- "Templates" |
| 14 |
- "Templates/Applications" |
| 15 |
state: present |
| 16 |
register: create_zabbix_template_result |
| 17 |
check_mode: true |
| 18 |
|
| 19 |
- ansible.builtin.assert: |
| 20 |
that: |
| 21 |
- create_zabbix_template_result.changed is sameas true |
| 22 |
|
| 23 |
- name: Create a new Zabbix template. |
| 24 |
community.zabbix.zabbix_template: |
| 25 |
template_name: ExampleHost |
| 26 |
template_groups: |
| 27 |
- "Templates" |
| 28 |
- "Templates/Applications" |
| 29 |
state: present |
| 30 |
register: create_zabbix_template_result |
| 31 |
|
| 32 |
- ansible.builtin.assert: |
| 33 |
that: |
| 34 |
- create_zabbix_template_result.changed is sameas true |
| 35 |
|
| 36 |
- name: Create a new Zabbix template (idempotency check). |
| 37 |
community.zabbix.zabbix_template: |
| 38 |
template_name: ExampleHost |
| 39 |
template_groups: |
| 40 |
- "Templates" |
| 41 |
- "Templates/Applications" |
| 42 |
state: present |
| 43 |
register: create_zabbix_template_result |
| 44 |
|
| 45 |
- ansible.builtin.assert: |
| 46 |
that: |
| 47 |
- create_zabbix_template_result.changed is sameas false |
| 48 |
|
| 49 |
- name: Create a new Zabbix template with linked templates. |
| 50 |
community.zabbix.zabbix_template: |
| 51 |
template_name: ExampleHostWithLinked |
| 52 |
template_groups: |
| 53 |
- "Templates" |
| 54 |
- "Templates/Applications" |
| 55 |
link_templates: |
| 56 |
- "Zabbix proxy health" |
| 57 |
- "FTP Service" |
| 58 |
state: present |
| 59 |
register: create_zabbix_template_linked_result |
| 60 |
|
| 61 |
- ansible.builtin.assert: |
| 62 |
that: |
| 63 |
- create_zabbix_template_linked_result.changed is sameas true |
| 64 |
|
| 65 |
- name: Gather Zabbix template infomation. |
| 66 |
community.zabbix.zabbix_template_info: |
| 67 |
template_name: ExampleHost |
| 68 |
format: json |
| 69 |
register: gather_template_result |
| 70 |
|
| 71 |
- name: "test - Set key to template_export_key variable(This deals with the key being masked)" |
| 72 |
ansible.builtin.set_fact: |
| 73 |
template_export_key: 'zabbix_export' |
| 74 |
|
| 75 |
- ansible.builtin.assert: |
| 76 |
that: |
| 77 |
- gather_template_result.template_json[template_export_key][template_groups_key].0.name == 'Templates' |
| 78 |
- gather_template_result.template_json[template_export_key][template_groups_key].1.name == 'Templates/Applications' |
| 79 |
|
| 80 |
- name: Add link_templates to Zabbix template. |
| 81 |
community.zabbix.zabbix_template: |
| 82 |
template_name: ExampleHost |
| 83 |
template_groups: |
| 84 |
- "Templates" |
| 85 |
- "Templates/Applications" |
| 86 |
link_templates: |
| 87 |
- "Zabbix proxy health" |
| 88 |
- "FTP Service" |
| 89 |
state: present |
| 90 |
register: update_zabbix_template_result |
| 91 |
|
| 92 |
- ansible.builtin.assert: |
| 93 |
that: |
| 94 |
- update_zabbix_template_result.changed is sameas true |
| 95 |
|
| 96 |
- name: Add link_templates to Zabbix template (idempotency check). |
| 97 |
community.zabbix.zabbix_template: |
| 98 |
template_name: ExampleHost |
| 99 |
template_groups: |
| 100 |
- "Templates" |
| 101 |
- "Templates/Applications" |
| 102 |
link_templates: |
| 103 |
- "Zabbix proxy health" |
| 104 |
- "FTP Service" |
| 105 |
state: present |
| 106 |
register: update_zabbix_template_result |
| 107 |
|
| 108 |
- ansible.builtin.assert: |
| 109 |
that: |
| 110 |
- update_zabbix_template_result.changed is sameas false |
| 111 |
|
| 112 |
- name: Gather Zabbix template infomation. |
| 113 |
community.zabbix.zabbix_template_info: |
| 114 |
template_name: ExampleHost |
| 115 |
format: json |
| 116 |
register: gather_template_result |
| 117 |
|
| 118 |
- ansible.builtin.assert: |
| 119 |
that: |
| 120 |
- gather_template_result.template_json[template_export_key][template_groups_key].0.name == 'Templates' |
| 121 |
- gather_template_result.template_json[template_export_key][template_groups_key].1.name == 'Templates/Applications' |
| 122 |
- gather_template_result.template_json[template_export_key].templates.0.templates.0.name == 'FTP Service' |
| 123 |
- gather_template_result.template_json[template_export_key].templates.0.templates.1.name == 'Zabbix proxy health' |
| 124 |
|
| 125 |
- name: Add macros to Zabbix template. |
| 126 |
community.zabbix.zabbix_template: |
| 127 |
template_name: ExampleHost |
| 128 |
template_groups: |
| 129 |
- "Templates" |
| 130 |
- "Templates/Applications" |
| 131 |
link_templates: |
| 132 |
- "Zabbix proxy health" |
| 133 |
- "FTP Service" |
| 134 |
macros: |
| 135 |
- macro: "{$EXAMPLE_MACRO1}" |
| 136 |
value: 1000 |
| 137 |
- macro: "{$EXAMPLE_MACRO2}" |
| 138 |
value: "text" |
| 139 |
state: present |
| 140 |
register: update_zabbix_template_result |
| 141 |
|
| 142 |
- ansible.builtin.assert: |
| 143 |
that: |
| 144 |
- update_zabbix_template_result.changed is sameas true |
| 145 |
|
| 146 |
- name: Add macros to Zabbix template (idempotency check). |
| 147 |
community.zabbix.zabbix_template: |
| 148 |
template_name: ExampleHost |
| 149 |
template_groups: |
| 150 |
- "Templates" |
| 151 |
- "Templates/Applications" |
| 152 |
link_templates: |
| 153 |
- "Zabbix proxy health" |
| 154 |
- "FTP Service" |
| 155 |
macros: |
| 156 |
- macro: "{$EXAMPLE_MACRO1}" |
| 157 |
value: 1000 |
| 158 |
- macro: "{$EXAMPLE_MACRO2}" |
| 159 |
value: "text" |
| 160 |
state: present |
| 161 |
register: update_zabbix_template_result |
| 162 |
|
| 163 |
- ansible.builtin.assert: |
| 164 |
that: |
| 165 |
- update_zabbix_template_result.changed is sameas false |
| 166 |
|
| 167 |
- name: Add tags to Zabbix template. |
| 168 |
community.zabbix.zabbix_template: |
| 169 |
template_name: ExampleHost |
| 170 |
template_groups: |
| 171 |
- "Templates" |
| 172 |
- "Templates/Applications" |
| 173 |
link_templates: |
| 174 |
- "Zabbix proxy health" |
| 175 |
- "FTP Service" |
| 176 |
macros: |
| 177 |
- macro: "{$EXAMPLE_MACRO1}" |
| 178 |
value: 1000 |
| 179 |
- macro: "{$EXAMPLE_MACRO2}" |
| 180 |
value: "text" |
| 181 |
tags: |
| 182 |
- tag: tag1 |
| 183 |
value: 1000 |
| 184 |
- tag: tag2 |
| 185 |
value: text |
| 186 |
state: present |
| 187 |
register: update_zabbix_template_result |
| 188 |
|
| 189 |
- ansible.builtin.assert: |
| 190 |
that: update_zabbix_template_result is changed |
| 191 |
|
| 192 |
- name: Add tags to Zabbix template (idempotency check). |
| 193 |
community.zabbix.zabbix_template: |
| 194 |
template_name: ExampleHost |
| 195 |
template_groups: |
| 196 |
- "Templates" |
| 197 |
- "Templates/Applications" |
| 198 |
link_templates: |
| 199 |
- "Zabbix proxy health" |
| 200 |
- "FTP Service" |
| 201 |
macros: |
| 202 |
- macro: "{$EXAMPLE_MACRO1}" |
| 203 |
value: 1000 |
| 204 |
- macro: "{$EXAMPLE_MACRO2}" |
| 205 |
value: "text" |
| 206 |
tags: |
| 207 |
- tag: tag1 |
| 208 |
value: 1000 |
| 209 |
- tag: tag2 |
| 210 |
value: text |
| 211 |
state: present |
| 212 |
register: update_zabbix_template_result |
| 213 |
|
| 214 |
- ansible.builtin.assert: |
| 215 |
that: update_zabbix_template_result is not changed |
| 216 |
|
| 217 |
- name: Remove tags from Zabbix template. |
| 218 |
community.zabbix.zabbix_template: |
| 219 |
template_name: ExampleHost |
| 220 |
template_groups: |
| 221 |
- "Templates" |
| 222 |
- "Templates/Applications" |
| 223 |
link_templates: |
| 224 |
- "Zabbix proxy health" |
| 225 |
- "FTP Service" |
| 226 |
macros: |
| 227 |
- macro: "{$EXAMPLE_MACRO1}" |
| 228 |
value: 1000 |
| 229 |
- macro: "{$EXAMPLE_MACRO2}" |
| 230 |
value: "text" |
| 231 |
tags: [] |
| 232 |
state: present |
| 233 |
register: update_zabbix_template_result |
| 234 |
|
| 235 |
- ansible.builtin.assert: |
| 236 |
that: update_zabbix_template_result is changed |
| 237 |
|
| 238 |
- name: Delete Zabbix template. |
| 239 |
community.zabbix.zabbix_template: |
| 240 |
template_name: ExampleHost |
| 241 |
state: absent |
| 242 |
register: delete_zabbix_template_result |
| 243 |
|
| 244 |
- ansible.builtin.assert: |
| 245 |
that: |
| 246 |
- delete_zabbix_template_result.changed is sameas true |
| 247 |
|
| 248 |
# |
| 249 |
# JSON Tests |
| 250 |
# |
| 251 |
|
| 252 |
- name: Import Zabbix template from JSON file (idempotency check). |
| 253 |
community.zabbix.zabbix_template: |
| 254 |
template_json: "{{ lookup('file', 'template3_54_higher.json') }}" |
| 255 |
state: present |
| 256 |
register: import_template_json |
| 257 |
|
| 258 |
- name: Assert Zabbix template from JSON file (idempotency check). |
| 259 |
ansible.builtin.assert: |
| 260 |
that: |
| 261 |
- import_template_json.changed is sameas true |
| 262 |
|
| 263 |
- name: Import Zabbix template from JSON file with matching values (idempotency check). |
| 264 |
community.zabbix.zabbix_template: |
| 265 |
template_json: "{{ lookup('file', 'template3_54_higher.json') }}" |
| 266 |
state: present |
| 267 |
register: import_template_json |
| 268 |
|
| 269 |
- name: Assert Zabbix template from JSON file with matching values (idempotency check). |
| 270 |
ansible.builtin.assert: |
| 271 |
that: |
| 272 |
- import_template_json.changed is sameas false |
| 273 |
|
| 274 |
- name: Gather Zabbix template infomation. |
| 275 |
community.zabbix.zabbix_template_info: |
| 276 |
template_name: ExampleHost |
| 277 |
format: json |
| 278 |
register: gather_template_result |
| 279 |
|
| 280 |
- block: |
| 281 |
- ansible.builtin.assert: |
| 282 |
that: |
| 283 |
- gather_template_result.template_json[template_export_key][template_groups_key].0.name == 'Templates' |
| 284 |
- gather_template_result.template_json[template_export_key][template_groups_key].1.name == 'Templates/Applications' |
| 285 |
- gather_template_result.template_json[template_export_key].templates.0.templates.0.name == 'FTP Service' |
| 286 |
- gather_template_result.template_json[template_export_key].templates.0.templates.1.name == 'Zabbix proxy health' |
| 287 |
- gather_template_result.template_json[template_export_key].templates.0.macros.0.macro == '{$EXAMPLE_MACRO1}' |
| 288 |
- gather_template_result.template_json[template_export_key].templates.0.macros.0.value == '1000' |
| 289 |
- gather_template_result.template_json[template_export_key].templates.0.macros.1.macro == '{$EXAMPLE_MACRO2}' |
| 290 |
- gather_template_result.template_json[template_export_key].templates.0.macros.1.value == 'text' |
| 291 |
|
| 292 |
- name: Import Zabbix template from JSON file with updated values. |
| 293 |
community.zabbix.zabbix_template: |
| 294 |
template_json: "{{ lookup('file', 'template3-changed_54_higher.json') }}" |
| 295 |
state: present |
| 296 |
register: import_template_json |
| 297 |
|
| 298 |
- ansible.builtin.assert: |
| 299 |
that: |
| 300 |
- import_template_json.changed is sameas true |
| 301 |
|
| 302 |
- name: Gather Zabbix template infomation. |
| 303 |
community.zabbix.zabbix_template_info: |
| 304 |
template_name: ExampleHost |
| 305 |
format: json |
| 306 |
register: gather_template_result |
| 307 |
|
| 308 |
- ansible.builtin.assert: |
| 309 |
that: |
| 310 |
- gather_template_result.template_json[template_export_key].templates.0.macros.0.macro == '{$EXAMPLE_MACRO1}' |
| 311 |
- gather_template_result.template_json[template_export_key].templates.0.macros.0.value == '1000' |
| 312 |
- gather_template_result.template_json[template_export_key].templates.0.macros.1.macro == '{$EXAMPLE_MACRO2}' |
| 313 |
- gather_template_result.template_json[template_export_key].templates.0.macros.1.value == 'text' |
| 314 |
- gather_template_result.template_json[template_export_key].templates.0.macros.2.macro == '{$EXAMPLE_MACRO3}' |
| 315 |
- gather_template_result.template_json[template_export_key].templates.0.macros.2.value == 'text2' |
| 316 |
|
| 317 |
# |
| 318 |
# xml |
| 319 |
# |
| 320 |
|
| 321 |
- block: |
| 322 |
- name: Import Zabbix template from XML file with updated values. |
| 323 |
community.zabbix.zabbix_template: |
| 324 |
template_xml: "{{ lookup('file', 'template3_54_higher.xml') }}" |
| 325 |
state: present |
| 326 |
register: import_template_xml |
| 327 |
|
| 328 |
- ansible.builtin.assert: |
| 329 |
that: |
| 330 |
- import_template_xml.changed is sameas true |
| 331 |
|
| 332 |
- name: Gather Zabbix template infomation. |
| 333 |
community.zabbix.zabbix_template_info: |
| 334 |
template_name: ExampleHost |
| 335 |
format: json |
| 336 |
register: gather_template_result |
| 337 |
|
| 338 |
# zabbix returns values sorted alphabetically so HTTP Service template comes before Zabbix Proxy template |
| 339 |
- block: |
| 340 |
- ansible.builtin.assert: |
| 341 |
that: |
| 342 |
- gather_template_result.template_json[template_export_key].templates.0.templates.0.name == 'FTP Service' |
| 343 |
- gather_template_result.template_json[template_export_key].templates.0.templates.1.name == 'Zabbix proxy health' |
| 344 |
|
| 345 |
# |
| 346 |
# Cleanup again |
| 347 |
# |
| 348 |
|
| 349 |
- name: Delete Zabbix template. |
| 350 |
community.zabbix.zabbix_template: |
| 351 |
template_name: ExampleHost |
| 352 |
state: absent |
| 353 |
register: delete_zabbix_template_result |
| 354 |
|
| 355 |
- ansible.builtin.assert: |
| 356 |
that: |
| 357 |
- delete_zabbix_template_result.changed is sameas true |
| 358 |
|
| 359 |
- name: Delete Zabbix template (idempotency check). |
| 360 |
community.zabbix.zabbix_template: |
| 361 |
template_name: ExampleHost |
| 362 |
state: absent |
| 363 |
register: delete_zabbix_template_result |
| 364 |
|
| 365 |
- ansible.builtin.assert: |
| 366 |
that: |
| 367 |
- delete_zabbix_template_result.changed is sameas false |
| 368 |
|
| 369 |
# |
| 370 |
# template_file_context parameter |
| 371 |
# |
| 372 |
|
| 373 |
- name: Import Zabbix template from a file using configuration.importcompare api |
| 374 |
block: |
| 375 |
- name: Import Zabbix template from YAML file. |
| 376 |
community.zabbix.zabbix_template: |
| 377 |
template_yaml: "{{ lookup('file', 'template4_60_higher.yaml') }}" |
| 378 |
state: present |
| 379 |
register: import_template_yaml |
| 380 |
|
| 381 |
- ansible.builtin.assert: |
| 382 |
that: |
| 383 |
- import_template_xml.changed is sameas true |
| 384 |
|
| 385 |
- name: Import Zabbix same template from XML file. |
| 386 |
community.zabbix.zabbix_template: |
| 387 |
template_xml: "{{ lookup('file', 'template4_60_higher.xml') }}" |
| 388 |
state: present |
| 389 |
register: import_same_template_xml |
| 390 |
|
| 391 |
- ansible.builtin.assert: |
| 392 |
that: |
| 393 |
- import_same_template_xml.changed is sameas false |
| 394 |
|
| 395 |
- name: Delete Zabbix template. |
| 396 |
community.zabbix.zabbix_template: |
| 397 |
template_name: ExampleTemplate |
| 398 |
state: absent |
| 399 |
register: delete_zabbix_template_result |
| 400 |
|
| 401 |
- ansible.builtin.assert: |
| 402 |
that: |
| 403 |
- delete_zabbix_template_result.changed is sameas true |
| 404 |
|
| 405 |
- name: Import Zabbix same template from XML file (after deleting template). |
| 406 |
community.zabbix.zabbix_template: |
| 407 |
template_xml: "{{ lookup('file', 'template4_60_higher.xml') }}" |
| 408 |
state: present |
| 409 |
register: import_same_template_xml |
| 410 |
|
| 411 |
- ansible.builtin.assert: |
| 412 |
that: |
| 413 |
- import_same_template_xml.changed is sameas true |
| 414 |
|
| 415 |
- name: Import Zabbix same template from JSON file. |
| 416 |
community.zabbix.zabbix_template: |
| 417 |
template_json: "{{ lookup('file', 'template4_60_higher.json') }}" |
| 418 |
state: present |
| 419 |
register: import_same_template_json |
| 420 |
|
| 421 |
- ansible.builtin.assert: |
| 422 |
that: |
| 423 |
- import_same_template_json.changed is sameas false |
| 424 |
|
| 425 |
- name: Delete Zabbix template. |
| 426 |
community.zabbix.zabbix_template: |
| 427 |
template_name: ExampleTemplate |
| 428 |
state: absent |
| 429 |
register: delete_zabbix_template_result |
| 430 |
|
| 431 |
- ansible.builtin.assert: |
| 432 |
that: |
| 433 |
- delete_zabbix_template_result.changed is sameas true |
| 434 |
|
| 435 |
- name: Delete Zabbix template (idempotency check). |
| 436 |
community.zabbix.zabbix_template: |
| 437 |
template_name: ExampleTemplate |
| 438 |
state: absent |
| 439 |
register: delete_zabbix_template_result |
| 440 |
|
| 441 |
- ansible.builtin.assert: |
| 442 |
that: |
| 443 |
- delete_zabbix_template_result.changed is sameas false |
| 444 |
|
| 445 |
|
| 446 |
# |
| 447 |
# Unicode stuff |
| 448 |
# |
| 449 |
|
| 450 |
# The test if decode Unicode correctly and to be imported the template. |
| 451 |
# https://github.com/ansible-collections/community.zabbix/issues/314 |
| 452 |
- name: Import Zabbix template from JSON file with unicode. |
| 453 |
community.zabbix.zabbix_template: |
| 454 |
template_json: "{{ lookup('file', 'template1_50_higher_decode_unicode.json') }}" |
| 455 |
state: present |
| 456 |
register: import_template_json |
| 457 |
|
| 458 |
- name: Gather Zabbix template infomation. |
| 459 |
community.zabbix.zabbix_template_info: |
| 460 |
template_name: ExampleTemplate314 |
| 461 |
format: json |
| 462 |
register: gather_template_result |
| 463 |
|
| 464 |
- ansible.builtin.assert: |
| 465 |
that: |
| 466 |
- import_template_json.changed is sameas true |
| 467 |
- gather_template_result.template_json.zabbix_export.templates.0.description == "\u30c6\u30b9\u30c8\u30b3\u30e1\u30f3\u30c8" |
| 468 |
|
| 469 |
- name: Delete Zabbix template. |
| 470 |
community.zabbix.zabbix_template: |
| 471 |
template_name: ExampleTemplate314 |
| 472 |
state: absent |
| 473 |
register: delete_zabbix_template_result |
| 474 |
|
| 475 |
- ansible.builtin.assert: |
| 476 |
that: |
| 477 |
- delete_zabbix_template_result.changed is sameas true |
| 478 |
|
| 479 |
- name: Clean up ExampleHostWithLinked template |
| 480 |
community.zabbix.zabbix_template: |
| 481 |
template_name: ExampleHostWithLinked |
| 482 |
state: absent |