From b255680a7ab8bd11634515afcef0d9e953f5b324 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Thu, 11 Aug 2022 21:04:07 -0400 Subject: [PATCH] Use host MariaDB in Gitea container --- dev/proxy.yml | 2 +- proxy.yml | 2 +- roles/.gitignore | 1 + roles/base/tasks/ansible.yml | 1 + roles/gitea/defaults/main.yml | 2 +- roles/gitea/tasks/main.yml | 15 ++++++++------- roles/mariadb/defaults/main.yml | 3 +++ roles/mariadb/tasks/main.yml | 25 +++++++++++++++++++++++++ 8 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 roles/mariadb/defaults/main.yml create mode 100644 roles/mariadb/tasks/main.yml diff --git a/dev/proxy.yml b/dev/proxy.yml index bd011b8..b01bc74 100644 --- a/dev/proxy.yml +++ b/dev/proxy.yml @@ -5,7 +5,7 @@ - host_vars/proxy.yml roles: - base - - postgresql + - mariadb - proxy - docker - gitea diff --git a/proxy.yml b/proxy.yml index 1f9f492..555480b 100644 --- a/proxy.yml +++ b/proxy.yml @@ -4,7 +4,7 @@ roles: - base - jenkins - - postgresql + - mariadb - proxy - docker - gitea diff --git a/roles/.gitignore b/roles/.gitignore index c5edb12..bb43362 100644 --- a/roles/.gitignore +++ b/roles/.gitignore @@ -7,6 +7,7 @@ !gitea*/ !jenkins*/ !libvirt*/ +!mariadb*/ !minecraft*/ !nextcloud*/ !nginx*/ diff --git a/roles/base/tasks/ansible.yml b/roles/base/tasks/ansible.yml index 37922de..c130855 100644 --- a/roles/base/tasks/ansible.yml +++ b/roles/base/tasks/ansible.yml @@ -13,6 +13,7 @@ loop: - aptitude - python3-docker + - python3-pymysql - python3-psycopg2 - name: Create Ansible's temporary remote directory diff --git a/roles/gitea/defaults/main.yml b/roles/gitea/defaults/main.yml index 328afb9..adefd91 100644 --- a/roles/gitea/defaults/main.yml +++ b/roles/gitea/defaults/main.yml @@ -9,7 +9,7 @@ gitea_rooturl: "http://{{ gitea_domain }}" gitea_signup: true # database settings -gitea_dbtype: postgres +gitea_dbtype: mysql gitea_dbhost: host.docker.internal gitea_dbname: "{{ gitea_name }}" gitea_dbuser: "{{ gitea_name }}" diff --git a/roles/gitea/tasks/main.yml b/roles/gitea/tasks/main.yml index 02e587c..5d3f20d 100644 --- a/roles/gitea/tasks/main.yml +++ b/roles/gitea/tasks/main.yml @@ -4,18 +4,19 @@ state: directory - name: Create Gitea database - postgresql_db: + mysql_db: name: "{{ gitea_dbname }}" - become: true - become_user: postgres + state: present + login_unix_socket: /var/run/mysqld/mysqld.sock - name: Create Gitea database user - postgresql_user: - db: "{{ gitea_dbname }}" + mysql_user: name: "{{ gitea_dbuser }}" password: "{{ gitea_dbpass }}" - become: true - become_user: postgres + host: '%' + state: present + priv: "{{ gitea_dbname }}.*:ALL" + login_unix_socket: /var/run/mysqld/mysqld.sock - name: Create git user user: diff --git a/roles/mariadb/defaults/main.yml b/roles/mariadb/defaults/main.yml new file mode 100644 index 0000000..78d6e67 --- /dev/null +++ b/roles/mariadb/defaults/main.yml @@ -0,0 +1,3 @@ +mariadb_trust: + - "172.16.0.0/12" + - "192.168.0.0/16" diff --git a/roles/mariadb/tasks/main.yml b/roles/mariadb/tasks/main.yml new file mode 100644 index 0000000..29c5f33 --- /dev/null +++ b/roles/mariadb/tasks/main.yml @@ -0,0 +1,25 @@ +- name: Install MariaDB + apt: + name: mariadb-server + state: present + +- name: Change the bind-address to allow Docker + lineinfile: + path: /etc/mysql/mariadb.conf.d/50-server.cnf + regex: "^bind-address" + line: "bind-address = 0.0.0.0" + register: mariadb_conf + +- name: Restart MariaDB + service: + name: mariadb + state: restarted + when: mariadb_conf.changed + +- name: Allow database connections + ufw: + rule: allow + port: "3306" + proto: tcp + src: "{{ item }}" + loop: "{{ mariadb_trust }}"