From 3012985b20e44c0ca4f7cce5a70926f518ec19c5 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Fri, 21 Aug 2015 17:44:30 -0400 Subject: Updates for zbx ans module --- roles/os_zabbix/tasks/clean_zabbix.yml | 47 ++++++++++++++++++++++++++ roles/os_zabbix/tasks/create_template.yml | 56 +++++++++++++++++++++++++++++++ roles/os_zabbix/tasks/create_user.yml | 11 ++++++ roles/os_zabbix/tasks/main.yml | 30 +++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 roles/os_zabbix/tasks/clean_zabbix.yml create mode 100644 roles/os_zabbix/tasks/create_template.yml create mode 100644 roles/os_zabbix/tasks/create_user.yml create mode 100644 roles/os_zabbix/tasks/main.yml (limited to 'roles/os_zabbix/tasks') diff --git a/roles/os_zabbix/tasks/clean_zabbix.yml b/roles/os_zabbix/tasks/clean_zabbix.yml new file mode 100644 index 000000000..1bcc07d42 --- /dev/null +++ b/roles/os_zabbix/tasks/clean_zabbix.yml @@ -0,0 +1,47 @@ +--- +- name: CLEAN List template for heartbeat + zbx_template: + server: "{{ server }}" + user: "{{ user }}" + password: "{{ password }}" + state: list + name: 'Template Heartbeat' + register: templ_heartbeat + +- name: CLEAN List template app zabbix server + zbx_template: + server: "{{ server }}" + user: "{{ user }}" + password: "{{ password }}" + state: list + name: 'Template App Zabbix Server' + register: templ_zabbix_server + +- name: CLEAN List template app zabbix server + zbx_template: + server: "{{ server }}" + user: "{{ user }}" + password: "{{ password }}" + state: list + name: 'Template App Zabbix Agent' + register: templ_zabbix_agent + +- name: CLEAN List all templates + zbx_template: + server: "{{ server }}" + user: "{{ user }}" + password: "{{ password }}" + state: list + register: templates + +- debug: var=templ_heartbeat.results + +- name: Remove templates if heartbeat template is missing + zbx_template: + server: "{{ server }}" + user: "{{ user }}" + password: "{{ password }}" + name: "{{ item }}" + state: absent + with_items: "{{ templates.results | difference(templ_zabbix_agent.results) | difference(templ_zabbix_server.results) | oo_collect('host') }}" + when: templ_heartbeat.results | length == 0 diff --git a/roles/os_zabbix/tasks/create_template.yml b/roles/os_zabbix/tasks/create_template.yml new file mode 100644 index 000000000..070390aba --- /dev/null +++ b/roles/os_zabbix/tasks/create_template.yml @@ -0,0 +1,56 @@ +--- +- debug: var=template + +- name: Template Create Template + zbx_template: + server: "{{ server }}" + user: "{{ user }}" + password: "{{ password }}" + name: "{{ template.name }}" + register: created_template + +- debug: var=created_template + +- name: Create Application + zbx_application: + server: "{{ server }}" + user: "{{ user }}" + password: "{{ password }}" + name: "{{ item }}" + template_name: "{{ template.name }}" + with_items: template.zapplications + register: created_application + when: template.zapplications is defined + +- debug: var=created_application + +- name: Create Items + zbx_item: + server: "{{ server }}" + user: "{{ user }}" + password: "{{ password }}" + key: "{{ item.key }}" + name: "{{ item.name | default(item.key, true) }}" + value_type: "{{ item.value_type | default('int') }}" + template_name: "{{ template.name }}" + applications: "{{ item.application }}" + with_items: template.zitems + register: created_items + when: template.zitems is defined + +#- debug: var=ctp_created_items + +- name: Create Triggers + zbx_trigger: + server: "{{ server }}" + user: "{{ user }}" + password: "{{ password }}" + description: "{{ item.description }}" + expression: "{{ item.expression }}" + priority: "{{ item.priority }}" + with_items: template.ztriggers + when: template.ztriggers is defined + +#- debug: var=ctp_created_triggers + + diff --git a/roles/os_zabbix/tasks/create_user.yml b/roles/os_zabbix/tasks/create_user.yml new file mode 100644 index 000000000..1f752a9e1 --- /dev/null +++ b/roles/os_zabbix/tasks/create_user.yml @@ -0,0 +1,11 @@ +--- +- name: Update zabbix credentialss for a user + zbx_user: + server: "{{ ozb_server }}" + user: "{{ ozb_user }}" + password: "{{ ozb_password }}" + alias: "{{ ozb_username }}" + passwd: "{{ ozb_new_password | default(ozb_password, true) }}" + register: user + +- debug: var=user.results diff --git a/roles/os_zabbix/tasks/main.yml b/roles/os_zabbix/tasks/main.yml new file mode 100644 index 000000000..06c0a09fc --- /dev/null +++ b/roles/os_zabbix/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: Main List all templates + zbx_template: + server: "{{ ozb_server }}" + user: "{{ ozb_user }}" + password: "{{ ozb_password }}" + state: list + register: templates + +- debug: var=templates + +- include_vars: template_heartbeat.yml +- include_vars: template_os_linux.yml + +- name: Include Template Heartbeat + include: create_template.yml + vars: + template: "{{ g_template_heartbeat }}" + server: "{{ ozb_server }}" + user: "{{ ozb_user }}" + password: "{{ ozb_password }}" + +#- name: Include Template os_linux +# include: create_template.yml +# vars: +# template: "{{ g_template_os_linux }}" +# server: "{{ ozb_server }}" +# user: "{{ ozb_user }}" +# password: "{{ ozb_password }}" + -- cgit v1.2.3