Add "zabbix-agent" role
authorAlexander Barton <alex@barton.de>
Wed, 21 Jan 2015 14:42:49 +0000 (15:42 +0100)
committerAlexander Barton <alex@barton.de>
Wed, 21 Jan 2015 14:42:49 +0000 (15:42 +0100)
This role downloads, installs, and configures the official
(non-Debian) Zabbix agent, see <http://www.zabbix.com/download.php>,
for Debian 7 "Wheezy".

roles/zabbix-agent/defaults/main.yml [new file with mode: 0644]
roles/zabbix-agent/handlers/main.yml [new file with mode: 0644]
roles/zabbix-agent/meta/main.yml [new file with mode: 0644]
roles/zabbix-agent/tasks/main.yml [new file with mode: 0644]
roles/zabbix-agent/templates/agent.conf.j2 [new file with mode: 0644]

diff --git a/roles/zabbix-agent/defaults/main.yml b/roles/zabbix-agent/defaults/main.yml
new file mode 100644 (file)
index 0000000..e28f8f9
--- /dev/null
@@ -0,0 +1,19 @@
+---
+# zabbix-agent defaults
+
+# Zabbix agent package for Debian
+zabbix_agent_pkg_file: "zabbix-agent_2.4.3-1+wheezy_amd64.deb"
+zabbix_agent_pkg_url: "http://repo.zabbix.com/zabbix/2.4/debian/pool/main/z/zabbix/{{ zabbix_agent_pkg_file }}"
+zabbix_agent_pkg_sha: "f9a0908a378c2262e07917ba4071ffbe44b632cba71938a47fab255f7a7f410d"
+
+# Zabbix server host (for "passive" agent checks, empty to disable)
+zabbix_agent_server: ""
+
+# Number of agent processes for "passive" checks (0 to disable)
+zabbix_agent_prefork: 0
+
+# Zabbix server host (for "active" agent checks, empty to disable)
+zabbix_agent_server_active: ""
+
+# Zabbix agent "HostMetadata" (for auto-registration)
+zabbix_agent_metadata: ""
diff --git a/roles/zabbix-agent/handlers/main.yml b/roles/zabbix-agent/handlers/main.yml
new file mode 100644 (file)
index 0000000..25df9e7
--- /dev/null
@@ -0,0 +1,7 @@
+---
+# zabbix-agent handlers
+
+- name: restart "zabbix-agent"
+  service: >
+    name=zabbix-agent
+    state=restarted
diff --git a/roles/zabbix-agent/meta/main.yml b/roles/zabbix-agent/meta/main.yml
new file mode 100644 (file)
index 0000000..979b5d5
--- /dev/null
@@ -0,0 +1,5 @@
+---
+# zabbix-agent meta
+
+dependencies:
+  - { role: debian-base }
diff --git a/roles/zabbix-agent/tasks/main.yml b/roles/zabbix-agent/tasks/main.yml
new file mode 100644 (file)
index 0000000..0118a4f
--- /dev/null
@@ -0,0 +1,51 @@
+---
+# zabbix-agent tasks
+
+- name: check if Zabbix agent is installed
+  tags:
+    - monitoring
+    - zabbix
+  shell: test -x /usr/sbin/zabbix_agentd
+  ignore_errors: yes
+  register: zabbix_agent_installed
+  changed_when: false
+  when: (zabbix_agent_server != "" or zabbix_agent_server_active != "")
+
+- name: download Zabbix agent package
+  tags:
+    - monitoring
+    - zabbix
+  get_url: url={{ zabbix_agent_pkg_url }} dest=/tmp/{{ zabbix_agent_pkg_file }} sha256sum={{ zabbix_agent_pkg_sha }}
+  when: (zabbix_agent_server != "" or zabbix_agent_server_active != "") and zabbix_agent_installed.rc != 0
+
+- name: install Zabbix agent package
+  tags:
+    - monitoring
+    - zabbix
+  shell: DEBIAN_FRONTEND=noninteractive dpkg -i /tmp/{{ zabbix_agent_pkg_file }}
+  when: (zabbix_agent_server != "" or zabbix_agent_server_active != "") and zabbix_agent_installed.rc != 0
+
+- name: setup "/etc/zabbix/zabbix_agentd.d/agent.conf"
+  tags:
+    - monitoring
+    - zabbix
+  template: >
+    dest=/etc/zabbix/zabbix_agentd.d/agent.conf
+    group=root
+    mode=644
+    owner=root
+    src=agent.conf.j2
+  notify:
+    - restart "zabbix-agent"
+  when: (zabbix_agent_server != "" or zabbix_agent_server_active != "")
+
+- name: ensure service "zabbix-agent" is enabled and running
+  tags:
+    - monitoring
+    - services
+    - zabbix
+  service: >
+    enabled=yes
+    name=zabbix-agent
+    state=running
+  when: (zabbix_agent_server != "" or zabbix_agent_server_active != "")
diff --git a/roles/zabbix-agent/templates/agent.conf.j2 b/roles/zabbix-agent/templates/agent.conf.j2
new file mode 100644 (file)
index 0000000..71cdf17
--- /dev/null
@@ -0,0 +1,14 @@
+# /etc/zabbix/zabbix_agentd.d/agent.conf
+# ---
+#  {{ ansible_managed }}
+# ---
+
+Hostname={{ inventory_hostname }}
+
+# Passive checks
+Server={{ zabbix_agent_server }}
+StartAgents={{ zabbix_agent_prefork }}
+
+# Active checks
+ServerActive={{ zabbix_agent_server_active }}
+HostMetadata={{ zabbix_agent_metadata }}