diff --git a/test/integration/targets/mysql_variables/aliases b/test/integration/targets/mysql_variables/aliases index 5eb727b09b1..a9bbc6febf0 100644 --- a/test/integration/targets/mysql_variables/aliases +++ b/test/integration/targets/mysql_variables/aliases @@ -2,3 +2,7 @@ destructive shippable/posix/group1 skip/osx skip/freebsd +skip/ubuntu +skip/fedora +skip/opensuse +skip/rhel diff --git a/test/integration/targets/mysql_variables/defaults/main.yml b/test/integration/targets/mysql_variables/defaults/main.yml index 2a0c459eede..e7860ac0263 100644 --- a/test/integration/targets/mysql_variables/defaults/main.yml +++ b/test/integration/targets/mysql_variables/defaults/main.yml @@ -1,4 +1,4 @@ --- # defaults file for test_mysql_variables user: 'user1' -password: 'khH&DYigjg' +password: 'khH&DYigjg1#' diff --git a/test/integration/targets/mysql_variables/meta/main.yml b/test/integration/targets/mysql_variables/meta/main.yml index 4aa170dc067..e7631b066fa 100644 --- a/test/integration/targets/mysql_variables/meta/main.yml +++ b/test/integration/targets/mysql_variables/meta/main.yml @@ -1,2 +1,2 @@ dependencies: - - setup_mysql_db + - setup_mysql8 diff --git a/test/integration/targets/mysql_variables/tasks/assert_var.yml b/test/integration/targets/mysql_variables/tasks/assert_var.yml index 7a3e963463f..1f4d2736b44 100644 --- a/test/integration/targets/mysql_variables/tasks/assert_var.yml +++ b/test/integration/targets/mysql_variables/tasks/assert_var.yml @@ -23,7 +23,7 @@ assert: { that: "output.changed == {{changed}}" } - name: run mysql command to show variable - command: mysql "-e show variables like '{{var_name}}';" + command: "mysql -uroot -p{{ root_pass }} \"-e show variables like '{{var_name}}';\"" register: result - name: assert output mysql variable name and value diff --git a/test/integration/targets/mysql_variables/tasks/assert_var_output.yml b/test/integration/targets/mysql_variables/tasks/assert_var_output.yml index 7214fa27dd8..869381679a3 100644 --- a/test/integration/targets/mysql_variables/tasks/assert_var_output.yml +++ b/test/integration/targets/mysql_variables/tasks/assert_var_output.yml @@ -27,7 +27,7 @@ key_value: "{{output.msg[0][0]}}" - name: run mysql command to show variable - command: mysql "-e show variables like '{{var_name}}';" + command: "mysql -uroot -p{{ root_pass }} \"-e show variables like '{{var_name}}';\"" register: result - name: assert output variable info match mysql variable info diff --git a/test/integration/targets/mysql_variables/tasks/main.yml b/test/integration/targets/mysql_variables/tasks/main.yml index 863d5509546..801fa7733b9 100644 --- a/test/integration/targets/mysql_variables/tasks/main.yml +++ b/test/integration/targets/mysql_variables/tasks/main.yml @@ -1,278 +1,2 @@ -# test code for the mysql_variables module -# (c) 2014, Wayne Rosario - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# ============================================================ -# Verify mysql_variable successfully queries a variable -# -- set_fact: set_name='version' - -- name: read mysql variables (expect changed=false) - mysql_variables: - variable: '{{set_name}}' - login_unix_socket: '{{ mysql_socket }}' - register: result - -- include: assert_var_output.yml changed=false output={{result}} var_name={{set_name}} - -# ============================================================ -# Verify mysql_variable successfully updates a variable (issue:4568) -# -- set_fact: - set_name: 'delay_key_write' - set_value: 'ON' - -- name: set mysql variable - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_unix_socket: '{{ mysql_socket }}' - -- name: update mysql variable to same value (expect changed=false) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_unix_socket: '{{ mysql_socket }}' - register: result - -- include: assert_var.yml changed=false output={{result}} var_name={{set_name}} var_value={{set_value}} - -# ============================================================ -# Verify mysql_variable successfully updates a variable using single quotes -# -- set_fact: - set_name: 'wait_timeout' - set_value: '300' - -- name: set mysql variable to a temp value - mysql_variables: - variable: '{{set_name}}' - value: '200' - login_unix_socket: '{{ mysql_socket }}' - -- name: update mysql variable value (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_unix_socket: '{{ mysql_socket }}' - register: result - -- assert: - that: - - result.queries == ["SET GLOBAL `{{ set_name }}` = {{ set_value }}"] - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -# ============================================================ -# Verify mysql_variable successfully updates a variable using double quotes -# -- set_fact: - set_name: "wait_timeout" - set_value: "400" - -- name: set mysql variable to a temp value - mysql_variables: - variable: '{{set_name}}' - value: "200" - login_unix_socket: '{{ mysql_socket }}' - -- name: update mysql variable value (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_unix_socket: '{{ mysql_socket }}' - register: result - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -# ============================================================ -# Verify mysql_variable successfully updates a variable using no quotes -# -- set_fact: - set_name: wait_timeout - set_value: 500 - -- name: set mysql variable to a temp value - mysql_variables: - variable: '{{set_name}}' - value: 200 - login_unix_socket: '{{ mysql_socket }}' - -- name: update mysql variable value (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_unix_socket: '{{ mysql_socket }}' - register: result - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -# ============================================================ -# Verify mysql_variable successfully updates a variable using an expression (e.g. 1024*4) -# -- name: set mysql variable value to an expression - mysql_variables: - variable: max_tmp_tables - value: "1024*4" - login_unix_socket: '{{ mysql_socket }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='Incorrect argument type to variable' - -# ============================================================ -# Verify mysql_variable fails when setting an incorrect value (out of range) -# -- name: set mysql variable value to a number out of range - mysql_variables: - variable: max_tmp_tables - value: -1 - login_unix_socket: '{{ mysql_socket }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='Truncated incorrect' - -# ============================================================ -# Verify mysql_variable fails when setting an incorrect value (incorrect type) -# -- name: set mysql variable value to a non-valid value number - mysql_variables: - variable: max_tmp_tables - value: TEST - login_unix_socket: '{{ mysql_socket }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='Incorrect argument type to variable' - -# ============================================================ -# Verify mysql_variable fails when setting an unknown variable -# -- name: set a non mysql variable - mysql_variables: - variable: my_sql_variable - value: ON - login_unix_socket: '{{ mysql_socket }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='Variable not available' - -# ============================================================ -# Verify mysql_variable fails when setting a read-only variable -# -- name: set value of a read only mysql variable - mysql_variables: - variable: character_set_system - value: utf16 - login_unix_socket: '{{ mysql_socket }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='read only variable' - -#============================================================= -# Verify mysql_variable works with the login_user and login_password parameters -# -- name: create mysql user - mysql_user: - name: '{{user}}' - password: '{{password}}' - state: present - priv: '*.*:ALL' - login_unix_socket: '{{ mysql_socket }}' - -- set_fact: - set_name: wait_timeout - set_value: 77 - -- name: query mysql_variable using login_user and password_password - mysql_variables: - variable: '{{set_name}}' - login_user: '{{user}}' - login_password: '{{password}}' - register: result - -- include: assert_var_output.yml changed=false output={{result}} var_name={{set_name}} - -- name: set mysql variable to temp value using user login and password (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: 20 - login_user: '{{user}}' - login_password: '{{password}}' - register: result - -- name: update mysql variable value using user login and password (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_user: '{{user}}' - login_password: '{{password}}' - register: result - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -#============================================================ -# Verify mysql_variable fails with an incorrect login_password parameter -# -- set_fact: - set_name: connect_timeout - set_value: 10 - -- name: query mysql_variable using incorrect login_password - mysql_variables: - variable: '{{set_name}}' - login_user: '{{user}}' - login_password: 'wrongpassword' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='unable to connect to database' - -- name: update mysql variable value using incorrect login_password (expect failed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_user: '{{user}}' - login_password: 'this is an incorrect password' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='unable to connect to database' - -#============================================================ -# Verify mysql_variable fails with an incorrect login_host parameter -# -- name: query mysql_variable using incorrect login_host - mysql_variables: - variable: wait_timeout - login_host: '12.0.0.9' - login_user: '{{user}}' - login_password: '{{password}}' - connect_timeout: 5 - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='unable to connect to database' - -- name: remove mysql_user {{user}} - mysql_user: - name: '{{user}}' - state: absent - login_unix_socket: '{{ mysql_socket }}' +- import_tasks: mysql_variables.yml + when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7' diff --git a/test/integration/targets/mysql_variables/tasks/mysql_variables.yml b/test/integration/targets/mysql_variables/tasks/mysql_variables.yml new file mode 100644 index 00000000000..5ebc4921225 --- /dev/null +++ b/test/integration/targets/mysql_variables/tasks/mysql_variables.yml @@ -0,0 +1,310 @@ +# test code for the mysql_variables module +# (c) 2014, Wayne Rosario + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# ============================================================ +# Verify mysql_variable successfully queries a variable +# +- set_fact: set_name='version' + +- name: read mysql variables (expect changed=false) + mysql_variables: + variable: '{{set_name}}' + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + +- include: assert_var_output.yml changed=false output={{result}} var_name={{set_name}} + +# ============================================================ +# Verify mysql_variable successfully updates a variable (issue:4568) +# +- set_fact: + set_name: 'delay_key_write' + set_value: 'ON' + +- name: set mysql variable + mysql_variables: + variable: '{{set_name}}' + value: '{{set_value}}' + login_user: root + login_password: '{{ root_pass }}' + login_unix_socket: '{{ mysql_socket }}' + +- name: update mysql variable to same value (expect changed=false) + mysql_variables: + variable: '{{set_name}}' + value: '{{set_value}}' + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + +- include: assert_var.yml changed=false output={{result}} var_name={{set_name}} var_value={{set_value}} + +# ============================================================ +# Verify mysql_variable successfully updates a variable using single quotes +# +- set_fact: + set_name: 'wait_timeout' + set_value: '300' + +- name: set mysql variable to a temp value + mysql_variables: + variable: '{{set_name}}' + value: '200' + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + +- name: update mysql variable value (expect changed=true) + mysql_variables: + variable: '{{set_name}}' + value: '{{set_value}}' + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + +- assert: + that: + - result.queries == ["SET GLOBAL `{{ set_name }}` = {{ set_value }}"] + +- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' + +# ============================================================ +# Verify mysql_variable successfully updates a variable using double quotes +# +- set_fact: + set_name: "wait_timeout" + set_value: "400" + +- name: set mysql variable to a temp value + mysql_variables: + variable: '{{set_name}}' + value: "200" + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + +- name: update mysql variable value (expect changed=true) + mysql_variables: + variable: '{{set_name}}' + value: '{{set_value}}' + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + +- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' + +# ============================================================ +# Verify mysql_variable successfully updates a variable using no quotes +# +- set_fact: + set_name: wait_timeout + set_value: 500 + +- name: set mysql variable to a temp value + mysql_variables: + variable: '{{set_name}}' + value: 200 + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + +- name: update mysql variable value (expect changed=true) + mysql_variables: + variable: '{{set_name}}' + value: '{{set_value}}' + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + +- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' + +# ============================================================ +# Verify mysql_variable successfully updates a variable using an expression (e.g. 1024*4) +# +- name: set mysql variable value to an expression + mysql_variables: + variable: max_tmp_tables + value: "1024*4" + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + ignore_errors: true + +- include: assert_fail_msg.yml output={{result}} msg='Incorrect argument type to variable' + +# ============================================================ +# Verify mysql_variable fails when setting an incorrect value (out of range) +# +- name: set mysql variable value to a number out of range + mysql_variables: + variable: max_tmp_tables + value: -1 + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + ignore_errors: true + +- include: assert_fail_msg.yml output={{result}} msg='Truncated incorrect' + +# ============================================================ +# Verify mysql_variable fails when setting an incorrect value (incorrect type) +# +- name: set mysql variable value to a non-valid value number + mysql_variables: + variable: max_tmp_tables + value: TEST + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + ignore_errors: true + +- include: assert_fail_msg.yml output={{result}} msg='Incorrect argument type to variable' + +# ============================================================ +# Verify mysql_variable fails when setting an unknown variable +# +- name: set a non mysql variable + mysql_variables: + variable: my_sql_variable + value: ON + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + ignore_errors: true + +- include: assert_fail_msg.yml output={{result}} msg='Variable not available' + +# ============================================================ +# Verify mysql_variable fails when setting a read-only variable +# +- name: set value of a read only mysql variable + mysql_variables: + variable: character_set_system + value: utf16 + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + register: result + ignore_errors: true + +- include: assert_fail_msg.yml output={{result}} msg='read only variable' + +#============================================================= +# Verify mysql_variable works with the login_user and login_password parameters +# +- name: create mysql user + mysql_user: + name: '{{user}}' + password: '{{password}}' + state: present + priv: '*.*:ALL' + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' + +- set_fact: + set_name: wait_timeout + set_value: 77 + +- name: query mysql_variable using login_user and password_password + mysql_variables: + variable: '{{set_name}}' + login_user: '{{user}}' + login_password: '{{password}}' + register: result + +- include: assert_var_output.yml changed=false output={{result}} var_name={{set_name}} + +- name: set mysql variable to temp value using user login and password (expect changed=true) + mysql_variables: + variable: '{{set_name}}' + value: 20 + login_user: '{{user}}' + login_password: '{{password}}' + register: result + +- name: update mysql variable value using user login and password (expect changed=true) + mysql_variables: + variable: '{{set_name}}' + value: '{{set_value}}' + login_user: '{{user}}' + login_password: '{{password}}' + register: result + +- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' + +#============================================================ +# Verify mysql_variable fails with an incorrect login_password parameter +# +- set_fact: + set_name: connect_timeout + set_value: 10 + +- name: query mysql_variable using incorrect login_password + mysql_variables: + variable: '{{set_name}}' + login_user: '{{user}}' + login_password: 'wrongpassword' + register: result + ignore_errors: true + +- include: assert_fail_msg.yml output={{result}} msg='unable to connect to database' + +- name: update mysql variable value using incorrect login_password (expect failed=true) + mysql_variables: + variable: '{{set_name}}' + value: '{{set_value}}' + login_user: '{{user}}' + login_password: 'this is an incorrect password' + register: result + ignore_errors: true + +- include: assert_fail_msg.yml output={{result}} msg='unable to connect to database' + +#============================================================ +# Verify mysql_variable fails with an incorrect login_host parameter +# +- name: query mysql_variable using incorrect login_host + mysql_variables: + variable: wait_timeout + login_host: '12.0.0.9' + login_user: '{{user}}' + login_password: '{{password}}' + connect_timeout: 5 + register: result + ignore_errors: true + +- include: assert_fail_msg.yml output={{result}} msg='unable to connect to database' + +- name: remove mysql_user {{user}} + mysql_user: + name: '{{user}}' + state: absent + login_unix_socket: '{{ mysql_socket }}' + login_user: root + login_password: '{{ root_pass }}' diff --git a/test/integration/targets/setup_mysql8/defaults/main.yml b/test/integration/targets/setup_mysql8/defaults/main.yml new file mode 100644 index 00000000000..c4461a888da --- /dev/null +++ b/test/integration/targets/setup_mysql8/defaults/main.yml @@ -0,0 +1,4 @@ +repo_link: https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm +repo_name: mysql-community +mysql_package_name: mysql-community-server +my_cnf: /etc/my.cnf diff --git a/test/integration/targets/setup_mysql8/files/my.cnf b/test/integration/targets/setup_mysql8/files/my.cnf new file mode 100644 index 00000000000..7fdc2afc268 --- /dev/null +++ b/test/integration/targets/setup_mysql8/files/my.cnf @@ -0,0 +1,7 @@ +[mysqld] +datadir=/var/lib/mysql +socket=/var/lib/mysql/mysql.sock +log-error=/var/log/mysqld.log +pid-file=/var/run/mysqld/mysqld.pid +default_authentication_plugin=mysql_native_password +skip-grant-tables diff --git a/test/integration/targets/setup_mysql8/tasks/main.yml b/test/integration/targets/setup_mysql8/tasks/main.yml new file mode 100644 index 00000000000..ed2c364e36f --- /dev/null +++ b/test/integration/targets/setup_mysql8/tasks/main.yml @@ -0,0 +1,6 @@ +# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# Setup MySQL 8: +- import_tasks: setup_mysql8.yml + when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7' diff --git a/test/integration/targets/setup_mysql8/tasks/setup_mysql8.yml b/test/integration/targets/setup_mysql8/tasks/setup_mysql8.yml new file mode 100644 index 00000000000..62b35446bc7 --- /dev/null +++ b/test/integration/targets/setup_mysql8/tasks/setup_mysql8.yml @@ -0,0 +1,59 @@ +# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +- name: Install Repo + yum: + name: '{{ repo_link }}' + +- name: Install MySQL community server + yum: + name: '{{ mysql_package_name }}' + +- name: Copy my.cnf + copy: + src: my.cnf + dest: '{{ my_cnf }}' + +- name: Start MySQL + service: + name: mysqld + state: started + +### Debug ####################### +#- name: Debug +# shell: cat /var/log/mysqld.log +################################# + +- name: Check connection to the server + shell: 'echo "SHOW DATABASES;" | mysql' + +- name: Check connection to the server + shell: "echo \"SHOW VARIABLES LIKE '%version%';\" | mysql" + +- name: Detect socket path + shell: > + echo "show variables like 'socket'\G" | mysql | grep 'Value: ' | sed 's/[ ]\+Value: //' + register: _socket_path + +- name: Set socket path + set_fact: + mysql_socket: '{{ _socket_path["stdout"] }}' + +- name: Set root pass + set_fact: + root_pass: "dlsafjlkjdsaK1#" + +- name: Set root password + shell: > + echo "flush privileges; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{{ root_pass }}';" | mysql + +- name: Change configuration + lineinfile: + path: '{{ my_cnf }}' + line: skip-grant-tables + state: absent + +- name: Restart MySQL + service: + name: mysqld + state: restarted