main.yml 3.19 KB
Newer Older
Florian Pritz's avatar
Florian Pritz committed
1
2
3
---

- name: install packages
Jelle van der Waa's avatar
Jelle van der Waa committed
4
  pacman: name=zabbix-agent,python-dbus,perl-json,arch-audit
Florian Pritz's avatar
Florian Pritz committed
5

6
- name: install packages for borg monitoring
7
  pacman: name=perl-json
8
9
  when: "'borg-clients' in group_names"

10
11
12
13
- name: install packages for nginx monitoring
  pacman: name=perl-json,perl-clone,perl-statistics-descriptive
  when: "'nginx' in group_names"

14
15
16
17
- name: install mysql userstats monitoring packages
  pacman: name=perl-dbi,perl-dbd-mysql,perl-json
  when: "'mysql-servers' in group_names"

Florian Pritz's avatar
Florian Pritz committed
18
19
20
- file: path=/etc/zabbix state=directory owner=root group=root mode=755

- name: create host PSK
21
  shell: umask 077; openssl rand -hex 64 > /etc/zabbix/zabbix_agentd.psk creates=/etc/zabbix/zabbix_agentd.psk
Florian Pritz's avatar
Florian Pritz committed
22
23
24
25

- name: fix permissions of PSK file
  file: path=/etc/zabbix/zabbix_agentd.psk owner=zabbix-agent group=zabbix-agent mode=600

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
- name: fetch PSK
  command: cat /etc/zabbix/zabbix_agentd.psk
  check_mode: no
  register: zabbix_agent_psk

- name: Set host config in zabbix
  local_action:
    module: zabbix_host
    server_url: "https://{{zabbix_agent_server}}"
    login_user: "{{vault_zabbix_admin_user}}"
    login_password: "{{vault_zabbix_admin_password}}"
    host_name: "{{inventory_hostname}}"
    visible_name: "{{inventory_hostname}}"
    link_templates: "{{zabbix_agent_templates}}"
    status: enabled
    state: present
    inventory_mode: disabled
    interfaces:
      - type: 1
        main: 1
        useip: "{{zabbix_agent_useip}}"
        ip: "{{zabbix_agent_ip}}"
        dns: "{{inventory_hostname}}"
        port: 10050
    tls_psk_identity: "PSK{{inventory_hostname}}"
    tls_accept: 2
    tls_connect: 2
    tls_psk: "{{zabbix_agent_psk.stdout}}"

Florian Pritz's avatar
Florian Pritz committed
55
56
57
58
59
- name: install agent config
  template: src=zabbix_agentd.conf dest=/etc/zabbix/zabbix_agentd.conf owner=zabbix-agent group=zabbix-agent mode=600
  notify:
    - restart zabbix agent

60
61
62
63
- name: Create mysql config for agent checks
  template: src=my.cnf.j2 dest=/etc/zabbix/zabbix_agentd.my.cnf owner=zabbix-agent group=zabbix-agent mode=600
  when: zabbix_agent_mysql_user is defined

64
65
66
67
- name: Install helper scripts
  copy: src={{item}} dest=/usr/local/bin/{{item}} mode=0755 owner=root group=root
  with_items:
    - systemd-units-failed.py
68
    - mysql-user-stats.pl
69
    - systemd-discover-accounting-units.py
70
    - zabbix-borg-timestamps.pl
71
    - mysql-dbsize-stats.pl
72

73
74
75
76
77
78
- name: Install helper scripts
  copy: src=nginx-zabbix.pl dest=/usr/local/bin/nginx-zabbix.pl mode=0755 owner=root group=root
  notify:
    - restart nginx-zabbix.service
  when: "'nginx' in group_names"

79
80
81
- name: install sudo config
  template: src=zabbix-agent-sudoers.conf.j2 dest=/etc/sudoers.d/zabbix-agent-sudoers

82
83
84
85
86
87
88
89
90
- name: copy nginx-zabbix.service
  copy: src=nginx-zabbix.service dest=/etc/systemd/system/nginx-zabbix.service owner=root group=root mode=0644
  notify:
    - restart nginx-zabbix.service
  when: "'nginx' in group_names"

- name: start nginx-zabbix.service
  service: name=nginx-zabbix.service enabled=yes state=started
  when: "'nginx' in group_names"
91

Florian Pritz's avatar
Florian Pritz committed
92
93
94
- name: run zabbix agent service
  service: name=zabbix-agent enabled=yes state=started

95
- name: open firewall holes
96
  firewalld: service=zabbix-agent permanent=true state=enabled immediate=yes
Florian Pritz's avatar
Florian Pritz committed
97
  when: configure_firewall
98
99
  tags:
    - firewall