Git history was lost when the previous Gitea instance was wiped and reinstalled due to an unresolved corruption bug — this commit is the last known-good file content, exported before the reinstall. Prior commit history is not recoverable through this path.
114 lines
3.2 KiB
YAML
114 lines
3.2 KiB
YAML
---
|
|
- name: Check if MariaDB is already installed
|
|
ansible.builtin.command: dpkg -l mariadb-server
|
|
register: mariadb_installed
|
|
failed_when: false
|
|
changed_when: false
|
|
|
|
- name: Check if MariaDB is running
|
|
ansible.builtin.systemd:
|
|
name: mariadb
|
|
register: mariadb_status
|
|
failed_when: false
|
|
changed_when: false
|
|
|
|
- name: Install MariaDB server (if not installed)
|
|
block:
|
|
- name: Install MariaDB packages
|
|
ansible.builtin.apt:
|
|
name:
|
|
- mariadb-server
|
|
- mariadb-client
|
|
- python3-pymysql
|
|
state: present
|
|
update_cache: yes
|
|
|
|
- name: Start and enable MariaDB
|
|
ansible.builtin.systemd:
|
|
name: mariadb
|
|
state: started
|
|
enabled: yes
|
|
when: mariadb_installed.rc != 0
|
|
|
|
- name: Check current root authentication method
|
|
ansible.builtin.shell: |
|
|
sudo mysql -e "SELECT plugin FROM mysql.user WHERE user='root' AND host='localhost';" -s -N
|
|
register: root_plugin
|
|
changed_when: false
|
|
ignore_errors: yes
|
|
|
|
- name: Switch root authentication from unix_socket to password
|
|
ansible.builtin.shell: |
|
|
sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '{{ mariadb_root_password }}';"
|
|
sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{{ mariadb_root_password }}';"
|
|
sudo mysql -e "FLUSH PRIVILEGES;"
|
|
when: root_plugin.stdout == 'unix_socket'
|
|
changed_when: true
|
|
|
|
- name: Create .my.cnf for root user
|
|
ansible.builtin.copy:
|
|
content: |
|
|
[client]
|
|
user=root
|
|
password={{ mariadb_root_password }}
|
|
dest: /root/.my.cnf
|
|
mode: '0600'
|
|
owner: root
|
|
group: root
|
|
|
|
- name: Test MySQL connection with password
|
|
ansible.builtin.command: mysql -u root -p{{ mariadb_root_password }} -e "SELECT 1"
|
|
register: mysql_test
|
|
changed_when: false
|
|
ignore_errors: yes
|
|
|
|
- name: Remove anonymous users
|
|
community.mysql.mysql_user:
|
|
name: ""
|
|
host_all: yes
|
|
login_user: root
|
|
login_password: "{{ mariadb_root_password }}"
|
|
state: absent
|
|
ignore_errors: yes
|
|
|
|
- name: Remove test database
|
|
community.mysql.mysql_db:
|
|
name: test
|
|
login_user: root
|
|
login_password: "{{ mariadb_root_password }}"
|
|
state: absent
|
|
ignore_errors: yes
|
|
|
|
- name: Check if database exists
|
|
ansible.builtin.command: mysql -u root -p{{ mariadb_root_password }} -e "USE {{ app_db_name }}"
|
|
register: db_exists
|
|
failed_when: false
|
|
changed_when: false
|
|
ignore_errors: yes
|
|
|
|
- name: Create osTicket database (if not exists)
|
|
community.mysql.mysql_db:
|
|
name: "{{ app_db_name }}"
|
|
login_user: root
|
|
login_password: "{{ mariadb_root_password }}"
|
|
state: present
|
|
when: db_exists.rc != 0
|
|
|
|
- name: Check if user exists
|
|
ansible.builtin.command: mysql -u root -p{{ mariadb_root_password }} -e "SELECT User FROM mysql.user WHERE User='{{ app_db_user }}'"
|
|
register: user_exists
|
|
failed_when: false
|
|
changed_when: false
|
|
ignore_errors: yes
|
|
|
|
- name: Create osTicket database user (if not exists)
|
|
community.mysql.mysql_user:
|
|
name: "{{ app_db_user }}"
|
|
password: "{{ app_db_password }}"
|
|
priv: "{{ app_db_name }}.*:ALL"
|
|
host: localhost
|
|
login_user: root
|
|
login_password: "{{ mariadb_root_password }}"
|
|
state: present
|
|
when: user_exists.rc != 0
|