Changeset - 62adfbb316a3
[Not reviewed]
0 3 0
Branko Majic (branko) - 5 years ago 2021-01-13 22:15:13
branko@majic.rs
MAR-151: Added support for Debian 10 Buster to database_server role:

- Updated role reference documentaiton.
- Updated role meta information.
- Updated tests.
- Deploy MariaDB client login configuration prior to setting-up
users/passwords for deprecated feature testing to avoid errors when
password gets changed in the middle of a task loop.
3 files changed with 23 insertions and 8 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -1997,96 +1997,97 @@ running a bare Django project):
 

	
 
    # Use wsgi_requirements to deploy Gunicorn.
 
    - role: wsgi_website
 
      fqdn: wsgi.example.com
 
      wsgi_application: wsgi:main
 
      wsgi_requirements:
 
        - gunicorn==19.7.1
 
	- futures==3.1.1
 

	
 

	
 
Database Server
 
---------------
 

	
 
The ``database_server`` role can be used for setting-up a MariaDB database
 
server on destination machine.
 

	
 
The role implements the following:
 

	
 
* Installs MariaDB server and client.
 
* Configures MariaDB server and client to use *UTF-8* encoding by default.
 
* Sets-up the database root user for passwordless login via UNIX
 
  socket authentication.
 
* Drops the ``debian-sys-maint`` database user (which was used in
 
  Debian Jessie and earlier for maintenance tasks) if it is present,
 
  and updates the Debian system maintenance configuration file to use
 
  the root account over unix socket authentication.
 

	
 

	
 
Role dependencies
 
~~~~~~~~~~~~~~~~~
 

	
 
Depends on the following roles:
 

	
 
* **common**
 

	
 

	
 
Parameters
 
~~~~~~~~~~
 

	
 
This role has no parameters.
 

	
 

	
 
Distribution compatibility
 
~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
Role is compatible with the following distributions:
 

	
 
- Debian 9 (Stretch)
 
- Debian 10 (Buster)
 

	
 

	
 
Examples
 
~~~~~~~~
 

	
 
This role has no parameters which can be configured configure.
 

	
 

	
 
Database
 
--------
 

	
 
The ``database`` role can be used for creating a MariaDB database and
 
accompanying user on destination machine.
 

	
 
The role implements the following:
 

	
 
* Creates MariaDB database.
 
* Creates a dedicated user capable of performing any operation on the created
 
  database. Username is set to be same as the name of database.
 
* Sets-up pre-backup task that creates database dump in location
 
  ``/srv/backup/mariadb/{{ db_name }}.sql``.
 

	
 

	
 
Role dependencies
 
~~~~~~~~~~~~~~~~~
 

	
 
Depends on the following roles:
 

	
 
* **database_server**
 
* **backup_client**
 

	
 

	
 
Backups
 
~~~~~~~
 

	
 
If the backup for this role has been enabled, the following paths are backed-up:
 

	
 
**/srv/backup/maraidb/{{ db_name }}.sql**
 
  Dump of the database. Database dump is created every day at 01:45 in the
 
  morning.
 

	
 

	
 
Parameters
 
~~~~~~~~~~
 

	
 
**db_name** (string, mandatory)
 
  Name of the database that should be created.
 

	
roles/database_server/molecule/default/molecule.yml
Show inline comments
 
---
 

	
 
dependency: {}
 

	
 
driver:
 
  name: vagrant
 
  provider:
 
    name: virtualbox
 

	
 
lint:
 
  name: yamllint
 
  options:
 
    config-file: ../../.yamllint.yml
 

	
 
platforms:
 

	
 
  - name: parameters-mandatory-stretch64
 
    groups:
 
      - parameters-mandatory
 
    box: debian/contrib-stretch64
 
    memory: 512
 
    cpus: 1
 

	
 
  - name: deprecated-stretch64
 
    groups:
 
      - deprecated
 
    box: debian/contrib-stretch64
 
    memory: 512
 
    cpus: 1
 

	
 
  - name: parameters-mandatory-buster64
 
    groups:
 
      - parameters-mandatory
 
    box: debian/contrib-buster64
 
    memory: 512
 
    cpus: 1
 

	
 
  - name: deprecated-buster64
 
    groups:
 
      - deprecated
 
    box: debian/contrib-buster64
 
    memory: 512
 
    cpus: 1
 

	
 
provisioner:
 
  name: ansible
 
  config_options:
 
    defaults:
 
      force_valid_group_names: "ignore"
 
      interpreter_python: "/usr/bin/python3"
 
    ssh_connection:
 
      pipelining: "True"
 
  lint:
 
    name: ansible-lint
 

	
 
scenario:
 
  name: default
 

	
 
verifier:
 
  name: testinfra
 
  lint:
 
    name: flake8
roles/database_server/molecule/default/prepare.yml
Show inline comments
 
---
 

	
 
- name: Prepare
 
  hosts: all
 
  gather_facts: false
 
  tasks:
 
    - name: Install python for Ansible
 
      raw: test -e /usr/bin/python3 || (apt -y update && apt install -y python3-minimal)
 
      become: true
 
      changed_when: false
 

	
 
- hosts: all
 
  become: true
 
  tasks:
 

	
 
    - name: Update all caches to avoid errors due to missing remote archives
 
      apt:
 
        update_cache: true
 
      changed_when: false
 

	
 
- hosts: deprecated
 
  become: true
 
  tasks:
 

	
 
    - 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: Deploy username and password for the root database user
 
      copy:
 
        src: "deprecated-root-my.cnf"
 
        dest: "/root/.my.cnf"
 
        owner: root
 
        group: root
 
        mode: 0400
 

	
 
    - name: Set password for the root database user (creating separate entry for different hosts)
 
      mysql_user:
 
        check_implicit_admin: true
 
        name: root
 
        host: "{{ item }}"
 
        password: "root_password"
 
      with_items:
 
        - "localhost"
 
        - "127.0.0.1"
 
        - "::1"
 
        - "{{ ansible_hostname }}"
 

	
 
    - name: Deploy username and password for the root database user
 
      copy:
 
        src: "deprecated-root-my.cnf"
 
        dest: "/root/.my.cnf"
 
        owner: root
 
        group: root
 
        mode: 0400
 

	
 
    - name: Disable use of unix socket login
 
      command: "mysql -B -e \"update mysql.user set plugin='' where user='root' and plugin='unix_socket'; flush privileges;\""
 

	
 
    - name: Create Debian system maintenance user
 
      mysql_user:
 
        name: debian-sys-maint
 
        password: debian-sys-maint-password
 

	
 
    - name: Deploy Debian system maintenance user login configuration
 
      copy:
 
        src: "deprecated-debian.cnf"
 
        dest: "/etc/mysql/debian.cnf"
 
        owner: root
 
        group: root
 
        mode: 0600
0 comments (0 inline, 0 general)