-
Notifications
You must be signed in to change notification settings - Fork 20
/
server.yml
55 lines (42 loc) · 1.57 KB
/
server.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
# Install server using a preseed file to set the root password
# 1) Check is MySQL Server is already installed. If so, do not set preseed file
- name: Check for previous installation
shell: "[ -f /usr/sbin/mysqld ]"
ignore_errors: True
register: mysqld_exists
# 2) Preseed install options
- name: Push preseed file for debconf
template:
src=mysql_seed.j2
dest=/root/mysql.seed
when: mysqld_exists|failed
- name: Preseed mysql file
command: /usr/bin/debconf-set-selections /root/mysql.seed
when: mysqld_exists|failed
# 3) Install
- name: Install server
apt: pkg=mysql-server state=installed force=yes
when: mysqld_exists|failed
- name: Ensure MySQL daemon is running
service: name=mysql state=started
# 4) Cleanup
- name: Delete mysql.seed file
command: /bin/rm /root/mysql.seed
when: mysqld_exists|failed
# Push configuration files
- name: Set my.cnf template
template:
src=my.cnf.j2
dest=/etc/mysql/my.cnf
owner=root mode=0644
notify:
- mysql-restart
# Secure installation
- name: Ensure python mysql is installed
apt: pkg=python-mysqldb state=installed force=yes
- name: Remove empty password users
mysql_user: name='' password='' host=localhost priv=*.*:USAGE state=absent login_user=root login_password={{ mysql_root_password }}
- name: Remove empty password users
mysql_user: name='' password='' host={{ ansible_fqdn }} priv=*.*:USAGE state=absent login_user=root login_password={{ mysql_root_password }}
- name: Remove the MySQL test database
mysql_db: db=test state=absent login_user=root login_password={{ mysql_root_password }}