inisital commit

This commit is contained in:
Olivier Barais
2021-12-02 11:43:36 +01:00
parent dd84b7dcab
commit 8545eb3d66
25 changed files with 515 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
---
# Handler to handle DB tier notifications
- name: restart mysql
service:
name: mysql
state: restarted
become: yes

View File

@@ -0,0 +1,78 @@
---
# This playbook will install mysql and create db user and give permissions.
- name: Install Mysql package
apt:
update_cache: true
name: ['mysql-server', 'python3-pip']
state: present
- name: Make sure pymysql is present
become: true # needed if the other tasks are not played as root
pip:
name: pymysql
state: present
- name: Create Mysql configuration file
template:
src: my.cnf.j2
dest: /etc/my.cnf
notify:
- restart mysql
- name: (DATABASE) Allow remote hosts to connect (Debian)
lineinfile:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
backrefs: yes
regexp: '^bind-address'
line: 'bind-address = 0.0.0.0'
state: present
notify: restart mysql
- name: Start Mysql Service
service:
name: mysql
state: started
enabled: yes
- name: Sets the root password
no_log: true
mysql_user:
name: root
password: "{{ mysql_root_password }}"
login_unix_socket: /var/run/mysqld/mysqld.sock
ignore_errors: yes
#- name: Removes all anonymous user accounts
# mysql_user:
# name: ''
# host_all: yes
# state: absent
#- name: Removes the MySQL test database
# mysql_db:
# name: test
# state: absent
- name: Create Application Database
mysql_db:
name: "{{ dbname }}"
login_user: root
login_password: "{{ mysql_root_password }}"
state: present
- name: Create Application DB User
no_log: true
mysql_user:
name: "{{ dbuser }}"
password: "{{ upassword }}"
login_unix_socket: /var/run/mysqld/mysqld.sock
priv: "*.*:ALL"
host: '%'
state: present
login_user: root
login_password: "{{ mysql_root_password }}"

View File

@@ -0,0 +1,12 @@
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
port={{ mysql_port }}
bind-address = 0.0.0.0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid