commit c5e60d80f9d855365127d29df845a9dde5b894ee Author: Patrick Neff Date: Mon Jan 24 19:01:07 2022 +0100 initial commit diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..357e0d3 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +mysql_users: [] +mysql_databases: [] diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..299df5a --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,4 @@ +galaxy_info: + role_name: mariadb + +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..cf9182f --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,52 @@ +- name: Install packages. + tags: mysql + ansible.builtin.package: + name: + - mariadb-server + - mariadb-client + - python3-pymysql + +- name: Remove unnecessary root accounts. + community.mysql.mysql_user: + name: root + host: "{{ item }}" + state: absent + with_items: + - 127.0.0.1 + - ::1 + - "{{ ansible_hostname }}" + +- name: Remove unnecessary anonymous accounts. + community.mysql.mysql_user: + name: "" + host: "{{ item }}" + state: absent + with_items: + - 127.0.0.1 + - ::1 + - "{{ ansible_hostname }}" + +- name: Remove test database. + community.mysql.mysql_db: + db: tests + state: absent + +- name: Create databases. + community.mysql.mysql_db: + login_unix_socket: /var/run/mysqld/mysqld.sock + encoding: "{{ item.encoding | default('utf8') }}" + target: "{{ item.target | default(omit) }}" + name: "{{ item.name }}" + state: present + with_items: "{{ mysql_databases }}" + +- name: Create database users. + tags: mysql + community.mysql.mysql_user: + login_unix_socket: /var/run/mysqld/mysqld.sock + name: "{{ item.name }}" + host: "{{ item.host }}" + password: "{{ item.password }}" + state: present + priv: "{{ item.priv }}" + with_items: "{{ mysql_users }}"