Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit a58e5bf

Browse files
author
Sebastian Gumprich
committed
add newmysql_cnf_owner variable, use ansible 2.0 features
1 parent 5a1e875 commit a58e5bf

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

defaults/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
mysql_hardening_enabled: yes
33

44
# general configuration
5-
mysql_hardening_user: 'mysql'
5+
mysql_cnf_owner: 'root' # owner of /etc/mysql/*.cnf files
6+
mysql_hardening_user: 'mysql' # owner of data
67
mysql_hardening_group: 'root'
78
mysql_datadir: '/var/lib/mysql'
89
mysql_hardening_mysql_hardening_conf_file: '{{mysql_hardening_mysql_confd_dir}}/hardening.cnf'
910
# You have to change this to your own strong enough mysql root password
1011
mysql_root_password: '-----====>SetR00tPa$$wordH3r3!!!<====-----'
11-
# There .my.cnf with mysql root credentials will be installed
12+
# There .my.cnf with mysql root credentials will be installed
1213
mysql_user_home: "{{ ansible_env.HOME}}"
1314

1415
# ensure the following parameters are set properly
@@ -47,3 +48,5 @@ mysql_hardening_options:
4748

4849
# @see https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option-mysqld-secure-file-priv
4950
secure-file-priv: '/tmp'
51+
# @see https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_user
52+
user: '{{mysql_hardening_user}}'

tasks/configure.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22

33
- name: protect my.cnf
4-
file: path='{{mysql_hardening_mysql_conf_file}}' mode=0400 owner='{{mysql_hardening_user}}' group='{{mysql_hardening_group}}' follow=yes
4+
file: path='{{mysql_hardening_mysql_conf_file}}' mode=0400 owner='{{mysql_cnf_owner}}' group='{{mysql_hardening_group}}' follow=yes state=file
55

66
- name: ensure permissions on mysql-datadir are correct
77
file: path='{{mysql_datadir}}' state=directory owner='{{mysql_hardening_user}}' group='{{mysql_hardening_user}}'
@@ -14,5 +14,8 @@
1414
notify: restart mysql
1515

1616
- name: apply hardening configuration
17-
template: src='hardening.cnf.j2' dest='{{mysql_hardening_mysql_hardening_conf_file}}' owner='{{mysql_hardening_user}}' group='{{mysql_hardening_group}}' mode=0460
17+
template: src='hardening.cnf.j2' dest='{{mysql_hardening_mysql_hardening_conf_file}}' owner='{{mysql_cnf_owner}}' group='{{mysql_hardening_group}}' mode=0460
1818
notify: restart mysql
19+
20+
- name: enable mysql
21+
service: name='{{ mysql_daemon }}' enabled=yes

tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
- include: configure.yml
1313
when: mysql_hardening_enabled
14-
tags:
14+
tags:
1515
- mysql_hardening
1616

1717
- include: mysql_secure_installation.yml
1818
when: mysql_hardening_enabled
19-
tags:
19+
tags:
2020
- mysql_hardening
2121
- mysql_secure_installation

tasks/mysql_secure_installation.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,17 @@
2424
- 'localhost'
2525

2626
- name: install .my.cnf with credentials
27-
template: src=my.cnf.j2 dest={{mysql_user_home}}/.my.cnf
27+
template: src=my.cnf.j2 dest={{mysql_user_home}}/.my.cnf
2828
mode=0400
2929
tags: my_cnf
3030

3131
- name: test database is absent
3232
mysql_db: name=test state=absent
3333
when: mysql_remove_test_database
3434

35-
# Can use only if ansible ver => 2.1
36-
#- name: anonymous users are absent
37-
# mysql_user: name='' state=absent host_all=yes
38-
# when: mysql_remove_anonymous_users
39-
40-
- name: copy mysql_remove_anonymous_users
41-
copy: src='{{item}}.sql' dest='/tmp/{{item}}.sql'
42-
with_items:
43-
- mysql_remove_anonymous_users
44-
when: mysql_remove_anonymous_users
45-
changed_when: false
46-
47-
- name: apply mysql_remove_anonymous_users
48-
mysql_db: name='mysql' state=import target='/tmp/{{item}}.sql'
49-
with_items:
50-
- mysql_remove_anonymous_users
35+
- name: anonymous users are absent
36+
mysql_user: name='' state=absent host_all=yes
5137
when: mysql_remove_anonymous_users
52-
changed_when: false
5338

5439
- name: copy mysql_remove_remote_root
5540
copy: src='{{item}}.sql' dest='/tmp/{{item}}.sql'
@@ -59,7 +44,7 @@
5944
changed_when: false
6045

6146
- name: apply mysql_remove_remote_root
62-
mysql_db: name='mysql' state=import target='/tmp/{{item}}.sql'
47+
mysql_db: name='mysql' state=import target='/tmp/{{item}}.sql'
6348
with_items:
6449
- mysql_remove_remote_root
6550
when: mysql_remove_remote_root

0 commit comments

Comments
 (0)