You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.0 KiB
94 lines
3.0 KiB
---
|
|
- name: Deploy Zabbix-Agent and Zabbix-Proxy with Docker
|
|
hosts: all
|
|
become: true
|
|
vars:
|
|
zabbix_version: "alpine-6.2-latest"
|
|
hostname: "{{ ansible_hostname }}"
|
|
# zabbix_server_host: "{{ hostvars['your_zabbix_server']['ansible_default_ipv4']['address'] }}"
|
|
zabbix_server_host: 87.128.173.178
|
|
zabbix_cachesize: "64M"
|
|
docker_network_name: "build"
|
|
docker_network_external: true
|
|
tasks:
|
|
- name: Ensure directory exists
|
|
file:
|
|
path: /mnt/docker/zabbix-agent
|
|
state: directory
|
|
owner: root
|
|
group: docker
|
|
mode: '0755'
|
|
|
|
- name: Create Docker Compose file
|
|
copy:
|
|
dest: /mnt/docker/zabbix-agent/docker-compose.yaml
|
|
content: |
|
|
version: "3"
|
|
services:
|
|
zabbix-agent:
|
|
image: zabbix/zabbix-agent2:{{ zabbix_version }}
|
|
container_name: zabbix-agent
|
|
hostname: zabbix-agent
|
|
restart: unless-stopped
|
|
privileged: true
|
|
user: root
|
|
healthcheck:
|
|
test: grep -qr "zabbix_agent2" /proc/*/status || exit 1
|
|
interval: 1m
|
|
timeout: 30s
|
|
retries: 3
|
|
environment:
|
|
- ZBX_HOSTNAME
|
|
- ZBX_SERVER_HOST=zabbix-proxy
|
|
- ZBX_ACTIVE_ALLOW
|
|
- ZBX_PASSIVE_ALLOW
|
|
volumes:
|
|
- /etc/localtime:/etc/localtime:ro
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
|
|
- ./dummy:/mnt/docker:ro
|
|
|
|
zabbix-proxy:
|
|
image: zabbix/zabbix-proxy-sqlite3:{{ zabbix_version }}
|
|
container_name: zabbix-proxy
|
|
hostname: zabbix-proxy
|
|
restart: unless-stopped
|
|
healthcheck:
|
|
test: grep -qr "zabbix_proxy" /proc/*/status || exit 1
|
|
interval: 1m
|
|
timeout: 30s
|
|
retries: 3
|
|
ports:
|
|
- 127.0.0.1:10051:10051
|
|
environment:
|
|
- ZBX_PROXYMODE=1
|
|
- ZBX_HOSTNAME
|
|
- ZBX_SERVER_HOST
|
|
- ZBX_CACHESIZE
|
|
volumes:
|
|
- ./snmptraps:/var/lib/zabbix/snmptraps
|
|
|
|
networks:
|
|
default:
|
|
name: {{ docker_network_name }}
|
|
external: {{ docker_network_external }}
|
|
|
|
- name: Create .env file
|
|
copy:
|
|
dest: /mnt/docker/zabbix-agent/.env
|
|
content: |
|
|
# settings for container
|
|
ZBX_HOSTNAME="{{ hostname }}"
|
|
ZBX_ACTIVE_ALLOW=false
|
|
ZBX_PASSIVE_ALLOW=true
|
|
ZBX_SERVER_HOST="{{ zabbix_server_host }}"
|
|
ZBX_CACHESIZE="{{ zabbix_cachesize }}"
|
|
mode: '0640'
|
|
owner: root
|
|
group: docker
|
|
|
|
- name: Run Docker Compose
|
|
community.docker.docker_compose:
|
|
project_src: /mnt/docker/zabbix-agent/
|
|
state: present
|
|
restarted: yes
|