This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmariadb-single.yml
84 lines (71 loc) · 2.11 KB
/
mariadb-single.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
- name: MariaDB Single Master Server Setup
hosts: master
vars:
- root_password: rootpswd
- db_username: user
- db_password: password
- database: newdb
become: true
tasks:
- name: Run Apt Update
ansible.builtin.apt:
update_cache: true
- name: Install Python and Pip for Ansible Script
ansible.builtin.apt:
name:
- python3
- python3-pip
- name: Install Python Module for Ansible MariaDB Automation
ansible.builtin.pip:
name:
- PyMySQL
- name: MariaDB Installation
ansible.builtin.apt:
name:
- mariadb-server
- mariadb-client
- name: add [mysqld] in my.cnf
ansible.builtin.lineinfile:
path: /etc/mysql/my.cnf
regexp: "\\[mysqld]"
line: "[mysqld]"
state: present
- name: Edit my.cnf
ansible.builtin.lineinfile:
path: /etc/mysql/my.cnf
regexp: 'bind-address = 0.0.0.0'
line: 'bind-address = 0.0.0.0'
state: present
- name: Restart and Enable MariaDB
ansible.builtin.service:
name: mysql
state: restarted
enabled: true
- name: Delete Anonymous user
community.mysql.mysql_user:
name: ''
host: localhost
state: absent
login_unix_socket: /run/mysqld/mysqld.sock
- name: Set Root Password with defined variable
community.mysql.mysql_user:
name: "root"
password: "{{root_password}}"
host: "{{item}}"
login_unix_socket: /run/mysqld/mysqld.sock
with_items:
- localhost
- name: Create Database "{{database}}"
community.mysql.mysql_db:
name: "{{database}}"
login_user: root
login_password: "{{root_password}}"
login_host: localhost
- name: "Create user {{db_username}} for database {{database}}"
community.mysql.mysql_user:
name: "{{db_username}}"
password: "{{db_password}}"
priv: "{{database}}.*:ALL,GRANT"
login_user: root
login_password: "{{root_password}}"
state: present