Files @ 449e6423959c
Branch filter:

Location: majic-ansible-roles/roles/database_server/tasks/main.yml - annotation

branko
MAR-151: Added support for Debian 10 Buster to xmpp_server role:

- Updated role reference documentaiton.
- Updated role meta information.
- Updated tests.
- Enable lower-level TLS protocols (1.0/1.1) in global OpenSSL
configuration file on Buster in order to be able to test the
xmpp_server_tls_protocol parameter (otherwise Prosody completely
refuses to use them even if listed in its configuration).
- Move stretch-specific tests into its own file (for backported
lua-ldap library), and run them on Debian 9 Stretch machines only.
---

- name: Install MariaDB
  apt:
    name:
      - mariadb-client
      - mariadb-server
      - python3-mysqldb
    state: present

- name: Enable and start MariaDB
  service:
    name: mysql
    state: started
    enabled: true

- name: Check if root user authentication is based on use of unix_socket module
  command: mysql --skip-column-names -B -e "select 1 from mysql.user where user='root' and host='localhost' and plugin='unix_socket';"
  register: "root_using_unix_socket_authentication"
  changed_when: false

# @TODO: It should be possible to replace this with mysql_user
#        invocation once MAR gets upgraded to use Ansible 2.10.x,
#        where mysql_user module has support for specifying the
#        authentication plugin. Once the switch is done, the above
#        task that registers the root_using_unix_socket_authentication
#        variable can be dropped as well.
- name: Set-up unix socket authentication for the root user
  command: mysql --skip-column-names -B -e "grant all privileges on *.* to root@localhost identified via unix_socket;"
  when: "not root_using_unix_socket_authentication.stdout"

- name: Check if there are any root-like database accounts available where host is not localhost
  command: mysql --skip-column-names -B -e "select 1 from mysql.user where user='root' and host!='localhost';"
  register: "additional_root_users"
  changed_when: false

- name: Drop all excess root user logins
  command:
    argv:
      - "mysql"
      - "-N"
      - "-B"
      - "-e"
      - "delete from mysql.user where User='root' and Host != 'localhost'; flush privileges;"
  when: "additional_root_users.stdout"

- name: Remove (now deprecated) my.cnf configuration file for the root database user
  file:
    path: "/root/.my.cnf"
    state: absent

- name: Check if Debian system maintenance configuration file uses the root account
  command: "grep -q 'user.*=.*root' /etc/mysql/debian.cnf"
  register: debian_maintenance_configuration_uses_root
  failed_when: false
  changed_when: false

- name: Deploy Debian system maintenance configuration file that uses root account
  copy:
    src: "debian.cnf"
    dest: "/etc/mysql/debian.cnf"
    owner: root
    group: root
    mode: 0600
  when: "debian_maintenance_configuration_uses_root.rc != 0"

- name: Drop the dedicated Debian system maintenance user
  mysql_user:
    name: "debian-sys-maint"
    state: absent

- name: Set UTF-8 encoding as default for MariaDB
  copy:
    src: "utf8.cnf"
    dest: "/etc/mysql/mariadb.conf.d/90-utf8.cnf"
    owner: root
    group: root
    mode: 0644
  register: mariadb_utf8_configuration

- name: Restart MariaDB in order to use UTF-8 as default character set  # noqa 503
  # [503] Tasks that run when changed should likely be handlers
  #   UTF-8 configuration must be applied immediatelly in order to ensure that
  #   subsequent tasks that create databases will end-up with correct (UTF-8)
  #   encoding. Otherwise they will be created using default latin1.
  service:
    name: mysql
    state: restarted
  when: mariadb_utf8_configuration.changed

- name: Explicitly run all handlers
  include: ../handlers/main.yml
  when: "run_handlers | default(False) | bool()"
  tags:
    - handlers