diff --git a/docs/rolereference.rst b/docs/rolereference.rst index 8a1cfe194a9c2466a6abb14bff5f2c040c0d54b2..d726766d015ae8f0facdf7e8ca0907837541de8d 100644 --- a/docs/rolereference.rst +++ b/docs/rolereference.rst @@ -1955,6 +1955,7 @@ Distribution compatibility Role is compatible with the following distributions: - Debian 8 (Jessie) +- Debian 9 (Stretch) Examples diff --git a/roles/database_server/molecule/default/molecule.yml b/roles/database_server/molecule/default/molecule.yml index e5c62d0ac461885dd1c5391d022dcee39cb2a168..9af56c1df16ce63078269a78972d65674ecbb18a 100644 --- a/roles/database_server/molecule/default/molecule.yml +++ b/roles/database_server/molecule/default/molecule.yml @@ -21,6 +21,13 @@ platforms: memory: 512 cpus: 1 + - name: parameters-mandatory-stretch64 + groups: + - parameters-mandatory + box: debian/contrib-stretch64 + memory: 512 + cpus: 1 + provisioner: name: ansible config_options: diff --git a/roles/database_server/molecule/default/tests/test_default.py b/roles/database_server/molecule/default/tests/test_default.py index 669bb73a7f167cc2d6c93c0da55573163c9ac63e..e3b2cefc5518f5285fb1d97fd9eb367ff9fb157b 100644 --- a/roles/database_server/molecule/default/tests/test_default.py +++ b/roles/database_server/molecule/default/tests/test_default.py @@ -74,20 +74,6 @@ def test_root_my_cnf_login(host): 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. diff --git a/roles/database_server/molecule/default/tests/test_default_jessie64.py b/roles/database_server/molecule/default/tests/test_default_jessie64.py new file mode 100644 index 0000000000000000000000000000000000000000..8dbf899ef9ab59282bacb72bbbc81d888941886c --- /dev/null +++ b/roles/database_server/molecule/default/tests/test_default_jessie64.py @@ -0,0 +1,31 @@ +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 diff --git a/roles/database_server/molecule/default/tests/test_default_stretch64.py b/roles/database_server/molecule/default/tests/test_default_stretch64.py new file mode 100644 index 0000000000000000000000000000000000000000..6ae1ba21fb7c49fd2717d5902ec52143b2856fb4 --- /dev/null +++ b/roles/database_server/molecule/default/tests/test_default_stretch64.py @@ -0,0 +1,31 @@ +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 diff --git a/roles/database_server/tasks/main.yml b/roles/database_server/tasks/main.yml index 2cc551597f234eb71df8f4a77956ead59982db33..28d08d137adf544045cddd4dc4a40865b4a8ab36 100644 --- a/roles/database_server/tasks/main.yml +++ b/roles/database_server/tasks/main.yml @@ -33,20 +33,48 @@ 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