Skip to content

Commit 768dda7

Browse files
committed
Extend users and database module with additional options
- Add additional config options, like - login_user - login_host - login_password - ca_certificate This also allows using this role for configuring users/databases for SaaS offerings, like Azure Database for MySQL. E.g. ```yaml - hosts: localhost vars: mysql_login_host: myazuredb.azure.net mysql_login_user: rootuser mysql_login_password: secret mysql_ca_cert: path/to/my/cert.pem tasks: - include_role: name: geerlingguy.mysql tasks_from: "{{ item }}" loop: - users - databases ``` Signed-off-by: szEvEz <szivos.john@gmail.com>
1 parent ea013c4 commit 768dda7

File tree

9 files changed

+38
-15
lines changed

9 files changed

+38
-15
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ mysql_bind_address: '0.0.0.0'
120120
mysql_datadir: /var/lib/mysql
121121
mysql_socket: *default value depends on OS*
122122
mysql_pid_file: *default value depends on OS*
123+
124+
mysql_login_host: ""
125+
mysql_login_user: ""
126+
mysql_login_password: ""
127+
mysql_ca_cert: ""
123128
```
124129

125130
Default MySQL connection configuration.

defaults/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ mysql_bind_address: '0.0.0.0'
4242
mysql_skip_name_resolve: false
4343
mysql_datadir: /var/lib/mysql
4444
mysql_sql_mode: ~
45+
46+
# Host running the database
47+
mysql_login_host: ""
48+
# The username and password used to authenticate with
49+
mysql_login_user: ""
50+
mysql_login_password: ""
51+
# The path to a Certificate Authority (CA) certificate.
52+
# This option, if used, must specify the same certificate as used by the server
53+
mysql_ca_cert: ""
54+
4555
# The following variables have a default value depending on operating system.
4656
# mysql_pid_file: /var/run/mysqld/mysqld.pid
4757
# mysql_socket: /var/lib/mysql/mysql.sock

handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: restart mysql
2+
- name: Restart mysql
33
ansible.builtin.service:
44
name: "{{ mysql_daemon }}"
55
state: restarted

tasks/configure.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
group: root
1414
mode: 0644
1515
force: "{{ overwrite_global_mycnf }}"
16-
notify: restart mysql
16+
notify: Restart mysql
1717

1818
- name: Verify mysql include directory exists.
1919
ansible.builtin.file:
@@ -33,7 +33,7 @@
3333
mode: 0644
3434
force: "{{ item.force | default(False) }}"
3535
with_items: "{{ mysql_config_include_files }}"
36-
notify: restart mysql
36+
notify: Restart mysql
3737

3838
- name: Create slow query log file (if configured).
3939
ansible.builtin.command: "touch {{ mysql_slow_query_log_file }}"

tasks/databases.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
---
22
- name: Ensure MySQL databases are present.
3-
mysql_db:
3+
community.mysql.mysql_db:
44
name: "{{ item.name }}"
55
collation: "{{ item.collation | default('utf8_general_ci') }}"
66
encoding: "{{ item.encoding | default('utf8') }}"
77
state: "{{ item.state | default('present') }}"
88
target: "{{ item.target | default(omit) }}"
9+
login_user: "{{ mysql_login_user | default(omit) }}"
10+
login_password: "{{ mysql_login_password | default(omit) }}"
11+
login_host: "{{ mysql_login_host | default(omit) }}"
12+
ca_cert: "{{ mysql_ca_cert | default(omit) }}"
913
with_items: "{{ mysql_databases }}"

tasks/replication.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Ensure replication user exists on master.
3-
mysql_user:
3+
community.mysql.mysql_user:
44
name: "{{ mysql_replication_user.name }}"
55
host: "{{ mysql_replication_user.host | default('%') }}"
66
password: "{{ mysql_replication_user.password }}"
@@ -14,7 +14,7 @@
1414
tags: ['skip_ansible_galaxy']
1515

1616
- name: Check slave replication status.
17-
mysql_replication:
17+
community.mysql.mysql_replication:
1818
mode: getreplica
1919
login_user: "{{ mysql_root_username }}"
2020
login_password: "{{ mysql_root_password }}"
@@ -28,7 +28,7 @@
2828

2929
# https://github.com/ansible/ansible/issues/82264
3030
- name: Check master replication status.
31-
mysql_replication:
31+
community.mysql.mysql_replication:
3232
mode: getprimary
3333
delegate_to: "{{ mysql_replication_master_inventory_host | default(omit, true) }}"
3434
register: master
@@ -39,7 +39,7 @@
3939
tags: ['skip_ansible_galaxy']
4040

4141
- name: Configure replication on the slave.
42-
mysql_replication:
42+
community.mysql.mysql_replication:
4343
mode: changeprimary
4444
master_host: "{{ mysql_replication_master }}"
4545
master_user: "{{ mysql_replication_user.name }}"
@@ -55,7 +55,7 @@
5555
- (mysql_replication_master | length) > 0
5656

5757
- name: Start replication.
58-
mysql_replication:
58+
community.mysql.mysql_replication:
5959
mode: startreplica
6060
when:
6161
- (slave.Is_Slave is defined and slave.Is_Slave) or (slave.Is_Replica is defined and slave.Is_Replica) or (slave.Is_Slave is not defined and slave.Is_Replica is not defined and slave is failed)

tasks/secure-installation.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Ensure default user is present.
3-
mysql_user:
3+
community.mysql.mysql_user:
44
name: "{{ mysql_user_name }}"
55
host: 'localhost'
66
password: "{{ mysql_user_password }}"
@@ -81,13 +81,13 @@
8181
check_mode: false
8282

8383
- name: Remove anonymous MySQL users.
84-
mysql_user:
84+
community.mysql.mysql_user:
8585
name: ""
8686
host: "{{ item }}"
8787
state: absent
8888
with_items: "{{ mysql_anonymous_hosts.stdout_lines|default([]) }}"
8989

9090
- name: Remove MySQL test database.
91-
mysql_db:
91+
community.mysql.mysql_db:
9292
name: 'test'
9393
state: absent

tasks/setup-Debian.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
- name: Update apt cache if MySQL is not yet installed.
88
ansible.builtin.apt:
9-
update_cache: yes
10-
changed_when: False
9+
update_cache: true
10+
changed_when: false
1111
when: not mysql_installed.stat.exists
1212

1313
- name: Ensure MySQL Python libraries are installed.

tasks/users.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
---
22
- name: Ensure MySQL users are present.
3-
mysql_user:
3+
community.mysql.mysql_user:
44
name: "{{ item.name }}"
55
host: "{{ item.host | default('localhost') }}"
66
password: "{{ item.password }}"
77
priv: "{{ item.priv | default('*.*:USAGE') }}"
88
state: "{{ item.state | default('present') }}"
99
append_privs: "{{ item.append_privs | default('no') }}"
1010
encrypted: "{{ item.encrypted | default('no') }}"
11+
login_user: "{{ mysql_login_user | default(omit) }}"
12+
login_password: "{{ mysql_login_password | default(omit) }}"
13+
login_host: "{{ mysql_login_host | default(omit) }}"
14+
ca_cert: "{{ mysql_ca_cert | default(omit) }}"
1115
with_items: "{{ mysql_users }}"
1216
no_log: "{{ mysql_hide_passwords }}"

0 commit comments

Comments
 (0)