You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
2.9 KiB

#
# task: install maraidb-server
#
# author Björn Hase, <herrhase@node001.net>
#
#
#
# check if maridb is already installed
#
- shell: dpkg -l | grep -e mariadb-server | cat
register: mariadb_installed
- name: if mariadb is already installed, end host
meta: end_host
when:
mariadb_installed.stdout | length > 0
#
# adding list in sources
#
- name: create the file, if it doesnt exist already
stat:
path: /etc/apt/sources.list.d/mariadb.list
register: list
#
# getting mariadb
#
- name: prepare install
shell: 'curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-{{ mariadb_version }}"'
when: not list.stat.exists
#
# adding packages
#
- name: mariadb / install
apt:
update_cache: yes
name:
- mariadb-server
- mariadb-client
- python3-mysqldb
#
# add user to mysql
#
- name: mariadb / add current user to mysql
user:
name: "{{ ansible_user }}"
groups: mysql
append: yes
#
# getting anonymous users and remove them
#
- name: Get list of hosts for the anonymous user.
community.mysql.mysql_query:
login_db: "mysql"
login_unix_socket: "{{ mariadb_socket }}"
query: SELECT Host FROM mysql.user WHERE User = %s
positional_args:
- ''
register: mariadb_anonymous_hosts
- name: Remove anonymous MariaDB users.
community.mysql.mysql_query:
login_db: "mysql"
login_unix_socket: "{{ mariadb_socket }}"
query: DELETE FROM mysql.user WHERE User=%s AND Host=%s
positional_args:
- ''
- "{{ item.Host }}"
loop: "{{ mariadb_anonymous_hosts.query_result | first }}"
when:
- not ansible_check_mode
- mariadb_anonymous_hosts.rowcount[0] != 0
#
# getting root users and remove remote root logins
#
- name: Get list of hosts for the root user.
community.mysql.mysql_query:
login_db: "mysql"
login_unix_socket: "{{ mariadb_socket }}"
query: SELECT Host FROM mysql.user WHERE User = %s ORDER BY (Host='localhost') ASC
positional_args:
- "{{ mariadb_admin_user }}"
register: mariadb_root_hosts
- name: Disallow root login remotely
community.mysql.mysql_user:
name: "{{ mariadb_admin_user }}"
login_unix_socket: "{{ mariadb_socket }}"
host: "{{ item.Host }}"
priv: "*.*:ALL,GRANT"
state: absent
loop: '{{ mariadb_root_hosts.query_result[0] | rejectattr("Host", "in", "localhost,::1,127.0.0.1") | list }}'
when: not ansible_check_mode
#
# remove all test databses
#
- name: Remove MariaDB test database.
community.mysql.mysql_db:
name: test
state: absent
login_unix_socket: "{{ mariadb_socket }}"
#
# Certificates
#
- include_tasks: certificates.yml
- include_tasks: chown.yml
#
# Configure
#
- include_tasks: configure.yml