-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible.yml
145 lines (121 loc) · 3.92 KB
/
ansible.yml
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
---
- hosts: localhost
tasks:
- name: Include vars of VARS.YML
include_vars: vars.yml
- name: install aptitude
apt:
name: aptitude
state: present
update_cache: yes
- name: Run apt upgrade ### second time run failing, try apt-get purge zabbix-agent
apt:
upgrade: "yes"
update_cache: yes
cache_valid_time: 432000
- name: Install a list of packages
apt:
name: "{{ Packages }}"
state: present
- name: Install the Python MySQLB module
pip:
name: MySQL-python
- name: Make sure mysql service is running
service:
name: mysql
state: started
enabled: True
- name: Update APT Package repository cache
apt:
update_cache: True
- name: Add key
apt_key:
url: https://repo.zabbix.com/zabbix-official-repo.key
state: present
- name: check for zabbix repo
stat:
path: /etc/apt/sources.list.d/zabbix-release_5.0-1+buster_all.deb.list
register: puppet4_repo
- name: Download zabbix
get_url:
url="https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-3+stretch_all.deb"
dest="/root/zabbix/zabbix-release_4.0-3+stretch_all.deb"
when: not puppet4_repo.stat.exists
- name: Update APT Package repository cache
apt:
update_cache: True
- name: Install zabbix
apt:
deb: zabbix-release_4.0-3+stretch_all.deb
when: not puppet4_repo.stat.exists
- name: Update APT Package repository cache
apt:
update_cache: True
- name: Install zabbix dependecies
apt:
name: zabbix-server-mysql,zabbix-frontend-php,zabbix-agent
state: present
- name: Update APT Package repository cache
apt:
update_cache: True
- name: Create a new database
mysql_db:
name: zabbix
state: present
- mysql_user:
name: "{{MysqlUserName}}"
password: "{{MysqlUserPassword}}"
priv: '*.*:ALL'
state: present
- name: check for create.sql
stat:
path: /usr/share/doc/zabbix-server-mysql/create.sql
register: aboba
- name: default ansible "unarchive" doesnt work becaues it uses only gtar/unzip, that cant unarchive .gz files
command:
cmd: gunzip /usr/share/doc/zabbix-server-mysql/create.sql.gz
when: not aboba
- name: databases | check for db existence
shell: >
mysql -e "show tables FROM zabbix"
register: mysql_exist
with_items: mysql_databases
ignore_errors: True
- name: Insert/Update "Match User" configuration block in /etc/zabbix/zabbix_server.conf
blockinfile:
dest: /etc/zabbix/zabbix_server.conf
block: |
DBHost=localhost
DBName=zabbix
DBUser="{{MysqlUserName}}"
DBPassword="{{MysqlUserPassword}}"
# - name: add timezone
# lineinfile:
# path: /etc/apache2/conf-available/zabbix.conf
# regexp: '# php_value date.timezone Europe/Riga'
# line: php_value date.timezone Europe/Riga
- name: Restart service httpd, in all cases
service:
name: apache2
state: restarted
- block:
- name: Import file.sql similar to mysql -u <username> -p <password> < hostname.sql
mysql_db:
login_password: "{{MysqlUserPassword}}"
login_user: "{{MysqlUserName}}"
login_host: localhost
state: import
name: zabbix
target: /usr/share/doc/zabbix-server-mysql/create.sql
when: not mysql_exist
ignore_errors: yes
- name: Restart service httpd, in all cases
service:
name: zabbix-server
state: restarted
- name: Restart service httpd, in all cases
service:
name: zabbix-agent
state: restarted
# INSTALL SELINUX TO RECEIVE ZABBIX-SERVER PID???? GIVE IT PERMISSIONS??? BLJAD KAKOGO HUJA
# sudo aptitude install zabbix-server-mysql zabbix-frontend-php zabbix-agent