create_template.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ---
  2. - name: Template Create Template
  3. zbx_template:
  4. zbx_server: "{{ server }}"
  5. zbx_user: "{{ user }}"
  6. zbx_password: "{{ password }}"
  7. name: "{{ template.name }}"
  8. register: created_template
  9. - set_fact:
  10. lzbx_item_applications: "{{ template.zitems | default([], True) | oo_select_keys_from_list(['applications']) | oo_flatten | unique }}"
  11. lzbx_itemprototype_applications: "{{ template.zitemprototypes | default([], True) | oo_select_keys_from_list(['applications']) | oo_flatten | unique }}"
  12. - name: Create Application
  13. zbx_application:
  14. zbx_server: "{{ server }}"
  15. zbx_user: "{{ user }}"
  16. zbx_password: "{{ password }}"
  17. name: "{{ item }}"
  18. template_name: "{{ template.name }}"
  19. with_items:
  20. - "{{ lzbx_item_applications }}"
  21. - "{{ lzbx_itemprototype_applications }}"
  22. register: created_application
  23. when: template.zitems is defined or template.zitemprototypes is defined
  24. - name: Create Items
  25. zbx_item:
  26. zbx_server: "{{ server }}"
  27. zbx_user: "{{ user }}"
  28. zbx_password: "{{ password }}"
  29. key: "{{ item.key }}"
  30. name: "{{ item.name | default(item.key, true) }}"
  31. value_type: "{{ item.value_type | default('int') }}"
  32. data_type: "{{ item.data_type | default('decimal') }}"
  33. description: "{{ item.description | default('', True) }}"
  34. multiplier: "{{ item.multiplier | default('', True) }}"
  35. units: "{{ item.units | default('', True) }}"
  36. template_name: "{{ template.name }}"
  37. applications: "{{ item.applications }}"
  38. zabbix_type: "{{ item.zabbix_type | default('trapper') }}"
  39. interval: "{{ item.interval | default(60, True) }}"
  40. delta: "{{ item.delta | default(0, True) }}"
  41. with_items: template.zitems
  42. register: created_items
  43. when: template.zitems is defined
  44. - name: Create Triggers
  45. zbx_trigger:
  46. zbx_server: "{{ server }}"
  47. zbx_user: "{{ user }}"
  48. zbx_password: "{{ password }}"
  49. name: "{{ item.name }}"
  50. description: "{{ item.description | default('', True) }}"
  51. dependencies: "{{ item.dependencies | default([], True) }}"
  52. expression: "{{ item.expression }}"
  53. priority: "{{ item.priority }}"
  54. url: "{{ item.url | default(None, True) }}"
  55. status: "{{ item.status | default('', True) }}"
  56. with_items: template.ztriggers
  57. when: template.ztriggers is defined
  58. - name: Create Actions
  59. zbx_action:
  60. zbx_server: "{{ server }}"
  61. zbx_user: "{{ user }}"
  62. zbx_password: "{{ password }}"
  63. state: "{{ item.state | default('present', True) }}"
  64. name: "{{ item.name }}"
  65. status: "{{ item.status | default('enabled', True) }}"
  66. escalation_time: "{{ item.escalation_time }}"
  67. conditions_filter: "{{ item.conditions_filter }}"
  68. operations: "{{ item.operations }}"
  69. with_items: template.zactions
  70. when: template.zactions is defined
  71. - name: Create Discoveryrules
  72. zbx_discoveryrule:
  73. zbx_server: "{{ server }}"
  74. zbx_user: "{{ user }}"
  75. zbx_password: "{{ password }}"
  76. name: "{{ item.name }}"
  77. key: "{{ item.key }}"
  78. lifetime: "{{ item.lifetime }}"
  79. template_name: "{{ template.name }}"
  80. description: "{{ item.description | default('', True) }}"
  81. with_items: template.zdiscoveryrules
  82. when: template.zdiscoveryrules is defined
  83. - name: Create Item Prototypes
  84. zbx_itemprototype:
  85. zbx_server: "{{ server }}"
  86. zbx_user: "{{ user }}"
  87. zbx_password: "{{ password }}"
  88. name: "{{ item.name }}"
  89. key: "{{ item.key }}"
  90. discoveryrule_key: "{{ item.discoveryrule_key }}"
  91. value_type: "{{ item.value_type }}"
  92. data_type: "{{ item.data_type | default('decimal') }}"
  93. template_name: "{{ template.name }}"
  94. applications: "{{ item.applications }}"
  95. description: "{{ item.description | default('', True) }}"
  96. multiplier: "{{ item.multiplier | default('', True) }}"
  97. units: "{{ item.units | default('', True) }}"
  98. interval: "{{ item.interval | default(60, True) }}"
  99. delta: "{{ item.delta | default(0, True) }}"
  100. with_items: template.zitemprototypes
  101. when: template.zitemprototypes is defined
  102. - name: Create Trigger Prototypes
  103. zbx_triggerprototype:
  104. zbx_server: "{{ server }}"
  105. zbx_user: "{{ user }}"
  106. zbx_password: "{{ password }}"
  107. name: "{{ item.name }}"
  108. expression: "{{ item.expression }}"
  109. url: "{{ item.url | default('', True) }}"
  110. priority: "{{ item.priority | default('average', True) }}"
  111. description: "{{ item.description | default('', True) }}"
  112. with_items: template.ztriggerprototypes
  113. when: template.ztriggerprototypes is defined
  114. - name: Create Graphs
  115. zbx_graph:
  116. zbx_server: "{{ server }}"
  117. zbx_user: "{{ user }}"
  118. zbx_password: "{{ password }}"
  119. name: "{{ item.name }}"
  120. height: "{{ item.height }}"
  121. width: "{{ item.width }}"
  122. graph_items: "{{ item.graph_items }}"
  123. with_items: template.zgraphs
  124. when: template.zgraphs is defined
  125. - name: Create Graph Prototypes
  126. zbx_graphprototype:
  127. zbx_server: "{{ server }}"
  128. zbx_user: "{{ user }}"
  129. zbx_password: "{{ password }}"
  130. name: "{{ item.name }}"
  131. height: "{{ item.height }}"
  132. width: "{{ item.width }}"
  133. graph_items: "{{ item.graph_items }}"
  134. with_items: template.zgraphprototypes
  135. when: template.zgraphprototypes is defined