Changeset - 30d5b3fa5b93
[Not reviewed]
0 4 2
Branko Majic (branko) - 7 years ago 2018-08-18 13:51:47
branko@majic.rs
MAR-132: Added support for Debian 9 (Stretch) to database_server role:

- Updated Molecule test configuration to include Debian 9 Stretch in
test matrix.
- Updated tests related to UTF-8 configuration (differences between
Debian 8 and 9).
- Deploy UTF-8 configuration in alternate locations depending on what
distro is being used.
- Force set-up of root password on Debian Stretch (default is to use
the unix_socket authentication).
6 files changed with 101 insertions and 17 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -1946,24 +1946,25 @@ Parameters
 
~~~~~~~~~~
 

	
 
**db_root_password** (string, mandatory)
 
  Password for the *root* database user.
 

	
 

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

	
 
Role is compatible with the following distributions:
 

	
 
- Debian 8 (Jessie)
 
- Debian 9 (Stretch)
 

	
 

	
 
Examples
 
~~~~~~~~
 

	
 
Here is an example configuration for setting-up the database server:
 

	
 
.. code-block:: yaml
 

	
 
   ---
 

	
 
   db_root_password: root
roles/database_server/molecule/default/molecule.yml
Show inline comments
 
@@ -12,24 +12,31 @@ lint:
 
  options:
 
    config-file: ../../.yamllint.yml
 

	
 
platforms:
 

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

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

	
 
provisioner:
 
  name: ansible
 
  config_options:
 
    ssh_connection:
 
      pipelining: "True"
 
  lint:
 
    name: ansible-lint
 

	
 
scenario:
 
  name: default
 

	
 
verifier:
roles/database_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -65,38 +65,24 @@ def test_root_my_cnf_login(host):
 
    configuration file.
 
    """
 

	
 
    with host.sudo():
 

	
 
        login = host.run("mysql -BNe 'show databases'")
 

	
 
        assert "information_schema" in login.stdout
 
        assert "mysql" in login.stdout
 
        assert "performance_schema" in login.stdout
 

	
 

	
 
def test_utf8_configuration_file(host):
 
    """
 
    Tests if UTF-8 database server configuration file has been deployed
 
    correctly.
 
    """
 

	
 
    config = host.file('/etc/mysql/conf.d/utf8.cnf')
 

	
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 

	
 

	
 
def test_utf8_configuration(host):
 
    """
 
    Tests if UTF-8 configuration has been applied correctly to server.
 
    """
 

	
 
    assert host.run("mysql -uroot -proot_password -BNe 'drop database if exists test'").rc == 0
 
    assert host.run("mysql -uroot -proot_password -BNe 'create database test'").rc == 0
 

	
 
    check_server = host.run("mysql -uroot -proot_password test -BNe 'select @@character_set_server; select @@collation_server'")
 

	
 
    assert check_server.rc == 0
 
    assert check_server.stdout == "utf8\nutf8_general_ci"
roles/database_server/molecule/default/tests/test_default_jessie64.py
Show inline comments
 
new file 100644
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory-jessie64'])
 

	
 

	
 
def test_utf8_configuration_file(host):
 
    """
 
    Tests if UTF-8 database server configuration file has been deployed
 
    correctly.
 
    """
 

	
 
    config = host.file('/etc/mysql/conf.d/utf8.cnf')
 

	
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 

	
 

	
 
def test_stretch_utf8_configuration_file_absent(host):
 
    """
 
    Tests if the Stretch configuration file is absent.
 
    """
 

	
 
    config = host.file('/etc/mysql/mariadb.conf.d/90-utf8.cnf')
 

	
 
    assert not config.exists
roles/database_server/molecule/default/tests/test_default_stretch64.py
Show inline comments
 
new file 100644
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory-stretch64'])
 

	
 

	
 
def test_utf8_configuration_file(host):
 
    """
 
    Tests if UTF-8 database server configuration file has been deployed
 
    correctly.
 
    """
 

	
 
    config = host.file('/etc/mysql/mariadb.conf.d/90-utf8.cnf')
 

	
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 

	
 

	
 
def test_jessie_utf8_configuration_file_absent(host):
 
    """
 
    Tests if the Jessie configuration file is absent.
 
    """
 

	
 
    config = host.file('/etc/mysql/conf.d/utf8.cnf')
 

	
 
    assert not config.exists
roles/database_server/tasks/main.yml
Show inline comments
 
@@ -24,38 +24,66 @@
 
    check_implicit_admin: true
 
    name: root
 
    password: "{{ db_root_password }}"
 

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

	
 
- name: Set UTF-8 encoding as default for MariaDB
 
- name: Check if root user authentication is based on use of unix_socket module (Stretch default)
 
  command: mysql --skip-column-names -B -e "select 1 from mysql.user where user='root' and plugin='unix_socket';"
 
  when: "ansible_distribution_release == 'stretch'"
 
  register: "root_using_unix_socket_authentication"
 
  changed_when: false
 

	
 
- name: Disable use of unix socket login on Debian Stretch (temporary workaround)
 
  command: "mysql -B -e \"update mysql.user set plugin='' where user='root' and plugin='unix_socket'; flush privileges;\""
 
  when: "ansible_distribution_release == 'stretch' and root_using_unix_socket_authentication.stdout != ''"
 

	
 
- name: Remove UTF-8 encoding configuration file from the old location on Debian Stretch
 
  file:
 
    path: "/etc/mysql/conf.d/utf8.cnf"
 
    state: absent
 
  when: "ansible_distribution_release == 'stretch'"
 
  register: mariadb_utf8_configuration_stretch
 

	
 
- name: Set UTF-8 encoding as default for MariaDB (on Jessie)
 
  copy:
 
    src: "utf8.cnf"
 
    dest: "/etc/mysql/conf.d/utf8.cnf"
 
    owner: root
 
    group: root
 
    mode: 0644
 
  register: mariadb_utf8_configuration
 
  when: "ansible_distribution_release == 'jessie'"
 
  register: mariadb_utf8_configuration_jessie
 

	
 
- name: Set UTF-8 encoding as default for MariaDB (on Stretch)
 
  copy:
 
    src: "utf8.cnf"
 
    dest: "/etc/mysql/mariadb.conf.d/90-utf8.cnf"
 
    owner: root
 
    group: root
 
    mode: 0644
 
  when: "ansible_distribution_release == 'stretch'"
 
  register: mariadb_utf8_configuration_stretch
 

	
 
- name: Restart MariaDB in order to use UTF-8 as default character set
 
  service:
 
    name: mysql
 
    state: restarted
 
  when: mariadb_utf8_configuration.changed
 
  when: mariadb_utf8_configuration_jessie.changed or mariadb_utf8_configuration_stretch.changed
 
  tags:
 
    # [ANSIBLE0016] 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.
 
    - skip_ansible_lint
 

	
 
- name: Explicitly run all handlers
 
  include: ../handlers/main.yml
 
  when: "handlers | default(False) | bool() == True"
 
  tags:
 
    - handlers
0 comments (0 inline, 0 general)