From c5e60d80f9d855365127d29df845a9dde5b894ee Mon Sep 17 00:00:00 2001 From: Patrick Neff Date: Mon, 24 Jan 2022 19:01:07 +0100 Subject: [PATCH] initial commit --- defaults/main.yml | 2 ++ meta/main.yml | 4 ++++ tasks/main.yml | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml 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 }}"