Skip to content

Commit 181aef9

Browse files
committed
Stylistic cleanup and reorganization.
1 parent a85ecf0 commit 181aef9

File tree

8 files changed

+72
-80
lines changed

8 files changed

+72
-80
lines changed

handlers/main.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
---
22
- name: restart mysql
3-
service: >
4-
name={{ mysql_daemon }}
5-
state=restarted
3+
service: "name={{ mysql_daemon }} state=restarted"

meta/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ galaxy_info:
1111
- name: EL
1212
versions:
1313
- 6
14+
- 7
1415
- name: Ubuntu
1516
versions:
1617
- all

tasks/configure.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- name: Copy my.cnf global MySQL configuration.
3+
template:
4+
src: my.cnf.j2
5+
dest: /etc/my.cnf
6+
owner: root
7+
group: root
8+
mode: 0644
9+
notify: restart mysql
10+
11+
- name: Ensure MySQL is started and enabled on boot.
12+
service: "name={{ mysql_daemon }} state=started enabled=yes"

tasks/databases-users.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: Ensure MySQL databases are present.
3+
mysql_db:
4+
name: "{{ item.name }}"
5+
collation: "{{ item.collation | default('utf8_general_ci') }}"
6+
encoding: "{{ item.encoding | default('utf8') }}"
7+
state: present
8+
with_items: mysql_databases
9+
10+
- name: Ensure MySQL users are present.
11+
mysql_user:
12+
name: "{{ item.name }}"
13+
host: "{{ item.host | default('localhost') }}"
14+
password: "{{ item.password }}"
15+
priv: "{{ item.priv | default('*.*:USAGE') }}"
16+
state: present
17+
with_items: mysql_users

tasks/main.yml

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,12 @@
22
- name: Include OS-specific variables.
33
include_vars: "{{ ansible_os_family }}.yml"
44

5-
- name: Update postfix to the latest version (if extra repositories enabled).
6-
yum: >
7-
name=postfix
8-
state=latest
9-
enablerepo={{ mysql_enablerepo }}
10-
when: mysql_enablerepo != ""
11-
125
- include: setup-RedHat.yml
136
when: ansible_os_family == 'RedHat'
147

158
- include: setup-Debian.yml
169
when: ansible_os_family == 'Debian'
1710

18-
- name: Copy my.cnf global MySQL configuration.
19-
template: >
20-
src=my.cnf.j2
21-
dest=/etc/my.cnf
22-
owner=root group=root mode=644
23-
notify: restart mysql
24-
25-
- name: Ensure MySQL is started and enabled on boot.
26-
service: >
27-
name={{ mysql_daemon }}
28-
state=started
29-
enabled=yes
30-
31-
- name: Check if .my.cnf file already exists.
32-
stat: "path={{ mysql_user_home }}/.my.cnf"
33-
register: mycnf_file
34-
35-
# 'localhost' needs to be the last item for idempotency, see
36-
# http://ansible.cc/docs/modules.html#mysql-user
37-
- name: Update MySQL root password for all root accounts.
38-
mysql_user: >
39-
name=root
40-
host={{ item }}
41-
password={{ mysql_root_password }}
42-
with_items:
43-
- 127.0.0.1
44-
- ::1
45-
- localhost
46-
when: mycnf_file.stat.exists == false
47-
48-
# Has to be after the root password assignment, for idempotency.
49-
- name: Copy .my.cnf file with root password credentials.
50-
template: >
51-
src=python-my.cnf.j2
52-
dest={{ mysql_user_home }}/.my.cnf
53-
owner=root group=root mode=600
54-
55-
- name: Delete anonymous MySQL user for localhost.
56-
mysql_user: >
57-
name=""
58-
state=absent
59-
60-
- name: Remove the MySQL test database.
61-
mysql_db: >
62-
name="test"
63-
state=absent
64-
65-
- name: Ensure MySQL databases are present.
66-
mysql_db: >
67-
name="{{ item.name }}"
68-
collation="{{ item.collation | default('utf8_general_ci') }}"
69-
encoding="{{ item.encoding | default('utf8') }}"
70-
state=present
71-
with_items: mysql_databases
72-
73-
- name: Ensure MySQL users are present.
74-
mysql_user: >
75-
name="{{ item.name }}"
76-
host="{{ item.host | default('localhost') }}"
77-
password="{{ item.password }}"
78-
priv="{{ item.priv | default('*.*:USAGE') }}"
79-
state=present
80-
with_items: mysql_users
11+
- include: configure.yml
12+
- include: secure-installation.yml
13+
- include: databases-users.yml

tasks/secure-installation.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
- name: Check if .my.cnf file already exists.
3+
stat: "path={{ mysql_user_home }}/.my.cnf"
4+
register: mycnf_file
5+
6+
# 'localhost' needs to be the last item for idempotency, see
7+
# http://ansible.cc/docs/modules.html#mysql-user
8+
- name: Update MySQL root password for all root accounts.
9+
mysql_user:
10+
name: "root"
11+
host: "{{ item }}"
12+
password: "{{ mysql_root_password }}"
13+
with_items:
14+
- 127.0.0.1
15+
- ::1
16+
- localhost
17+
when: mycnf_file.stat.exists == false
18+
19+
# Has to be after the root password assignment, for idempotency.
20+
- name: Copy .my.cnf file with root password credentials.
21+
template:
22+
src: "python-my.cnf.j2"
23+
dest: "{{ mysql_user_home }}/.my.cnf"
24+
owner: root
25+
group: root
26+
mode: 0600
27+
28+
- name: Remove anonymous MySQL user.
29+
mysql_user: "name='' state=absent"
30+
31+
- name: Remove MySQL test database.
32+
mysql_db: "name='test' state=absent"

tasks/setup-Debian.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@
88
when: mysql_installed.stat.exists == false
99

1010
- name: Ensure MySQL packages are installed.
11-
apt: >
12-
name={{ item }}
13-
state=installed
11+
apt: "name={{ item }} state=installed"
1412
with_items: mysql_packages

tasks/setup-RedHat.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
2+
- name: Update postfix to the latest version (if extra repositories enabled).
3+
yum: "name=postfix state=latest enablerepo={{ mysql_enablerepo }}"
4+
when: mysql_enablerepo != ""
5+
26
- name: Ensure MySQL packages are installed.
3-
yum: >
4-
name={{ item }}
5-
state=installed
6-
enablerepo={{ mysql_enablerepo }}
7+
yum: "name={{ item }} state=installed enablerepo={{ mysql_enablerepo }}"
78
with_items: mysql_packages

0 commit comments

Comments
 (0)