-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzbx.yaml
218 lines (181 loc) · 6.51 KB
/
zbx.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#
#
# Necessário no centos ter epel-relase, redhat-lsb, wget instalado
#
---
- hosts: all
user: charles.a
connection: ssh
become_user: root
become: false
become_method: sudo
gather_facts: true
vars:
zbx_ver: "4.2" #versao zabbix
zbx_sub_ver: "-3" #subversao do zabbix-agent
zbx_Server: "x.x.x.x" #servidor do zabbix
zbx_ServerActive: "y.y.y.y" #servidor do zabbix
zbx_confDir: "/etc/zabbix/" #diretorio de configuração destino
zbx_confArq: "zabbix_agentd.conf" #arquivo de configuração
work_dir: "./" #arquivo local
zbx_admin: "xxxxx" #usuario com permissão para add hosts no zabbix
zbx_passwd: "xxxxxxxxxxxx" #senha do usuario com permissao para add hosts
zbx_url: "http://xxxxx/zabbix" #url do zabbix
tasks:
- name: install Python e agent zabbix
apt:
name: ['python', 'python-pip']
update_cache: yes
state: present
when: (ansible_os_family == "Debian") or (ansible_os_family == "Ubuntu")
tags: instalar
- name: Desliga SELinux
selinux:
policy: targeted
state: permissive
when: ansible_distribution == "CentOS" or (ansible_os_family == "RedHat")
- name: Removendo Zabbix-Agent
apt:
name: zabbix-agent
state: absent
when: (ansible_os_family == "Debian") or (ansible_os_family == "Ubuntu")
ignore_errors: yes
tags: instalar
- name: Removendo Zabbix-Agent
yum:
name: zabbix-agent
state: absent
when: (ansible_os_family == "Centos") or (ansible_os_family == "RedHat")
ignore_errors: yes
tags: instalar
- name: Registro de sistema operacional
shell: lsb_release -si | tr 'A-Z' 'a-z'
register: SO
tags: [instalar, conf, add]
- name: Registro da versao do sistema operacional
shell: lsb_release -sc
register: SOVERSION
tags: [instalar, conf, add]
- name: Registro da versao short do sistema operacional
shell: lsb_release -sr | cut -c1-1
register: SOSHOT
tags: [instalar, conf, add]
- name: Registro do nome da maquina
shell: hostname
register: hname
tags: [instalar, conf, add]
- name: Registro de IP
shell: hostname -I | awk '{print $1}'
register: hip
tags: [instalar, conf, add]
- name: Registro de pacote debian instalado
shell: dpkg -l | grep zabbix-agent; echo $?
register: ipack
when: (ansible_os_family == "Debian") or (ansible_os_family == "Ubuntu")
tags: instalar
- name: Registro de pacote centos instalado
shell: rpm -qa | grep zabbix; echo $?
register: ipack
when: (ansible_os_family == "Centos") or (ansible_os_family == "RedHat")
tags: instalar
- name: Removendo bibliotecas Zabbix-Agent .deb
action: raw dpkg --purge zabbix-release && dpkg --purge zabbix-agent
when: ipack.stdout != "1"
tags: instalar
- name: Removendo bibliotecas Zabbix-Agent .rpm
action: raw rpm -e zabbix*
when: ipack.stdout != "1"
tags: instalar
- debug: var={{ item }}
with_items:
- SO.stdout
- SOVERSION.stdout
- SOSHOT.stdout
- hname.stdout
- hip.stdout
- ipck.stdout
- zbx_ver
- zbx_sub_ver
tags: [instalar, confi, add]
- name: Baixando biblioteca Zabbix-Agent
action: raw wget https://repo.zabbix.com/zabbix/{{ zbx_ver }}/{{ SO.stdout }}/pool/main/z/zabbix-release/zabbix-release_{{ zbx_ver }}{{ zbx_sub_ver }}+{{ SOVERSION.stdout }}_all.deb
when: (ansible_os_family == "Debian") or (ansible_os_family == "Ubuntu")
tags: instalar
- name: Executando novos repositorios .deb
action: raw dpkg -i zabbix-release_{{ zbx_ver }}{{ zbx_sub_ver }}+{{ SOVERSION.stdout }}_all.deb
when: (ansible_os_family == "Debian") or (ansible_os_family == "Ubuntu")
tags: instalar
- name: Atualizando repositorios
action: raw apt-get update
when: (ansible_os_family == "Debian") or (ansible_os_family == "Ubuntu")
tags: instalar
- name: Install agent-zabbix
apt:
name: zabbix-agent
state: present
when: (ansible_os_family == "Debian") or (ansible_os_family == "Ubuntu")
tags: instalar
- name: Baixando biblioteca Zabbix-Agent
action: raw wget https://repo.zabbix.com/zabbix/{{ zbx_ver }}/rhel/{{ SOSHOT.stdout }}/x86_64/zabbix-release-{{ zbx_ver }}{{ zbx_sub_ver }}{{ SOSHOT.stdout }}.noarch.rpm
when: (ansible_os_family == "Centos") or (ansible_os_family == "RedHat")
tags: instalar
- name: Executando novos repositorios .rpm
action: raw rpm -Uvh zabbix-release-{{ zbx_ver }}{{ zbx_sub_ver }}{{ SOSHOT.stdout }}.noarch.rpm
when: (ansible_os_family == "Centos") or (ansible_os_family == "RedHat")
tags: instalar
- name: Instalando zabbix-agent
action: raw yum -y install zabbix-agent
when: (ansible_os_family == "Centos") or (ansible_os_family == "RedHat")
tags: instalar
- name: Copiando arquivo de configuracao do zabbix-agent
copy:
src: "{{ work_dir }}{{ zbx_confArq }}"
dest: "{{ zbx_confDir }}{{ zbx_confArq }}"
backup: yes
tags: conf
- name: Modifca algumas linhas do zabbix
lineinfile:
backup=yes
dest="{{ zbx_confDir }}{{ zbx_confArq }}"
regexp="{{ item.regexp }}"
line="{{ item.line }}"
with_items:
- { regexp: '(?i)^Hostname=', line: 'Hostname={{ hname.stdout }} ' }
- { regexp: '(?i)^Server=', line: 'Server={{ zbx_Server }} ' }
- { regexp: '(?i)^ServerActive=', line: 'ServerActive={{ zbx_ServerActive }} ' }
tags: conf
- name: Colocando a maquina no monitoramento
become: false
local_action:
module: zabbix_host
server_url: "{{ zbx_url }}"
login_user: "{{ zbx_admin }}"
login_password: "{{ zbx_passwd }}"
validate_certs: no
host_name: "{{ hname.stdout }}"
visible_name: "{{ hname.stdout }}"
description: Instalacao e configuracao via ansible
host_groups:
- Linux servers
- MTMON
link_templates:
- Template OS Linux
status: enabled
interfaces:
- type: 1
main: 1
useip: 1
ip: "{{ hip.stdout }}"
dns: ""
port: 10050
inventory_mode: manual
inventory_zabbix:
os: "{{ SO.stdout }} {{ SOVERSION.stdout }}"
tags: add
- name: make sure the zabbix-agent service is running
service:
name: zabbix-agent
state: started
enabled: True
become: True
tags: conf