mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-06 10:40:36 -07:00
updated integration tests
This commit is contained in:
parent
815ad0de99
commit
e4faab0e57
120 changed files with 2326 additions and 2281 deletions
6
.github/workflows/ansible-test-roles.yml
vendored
6
.github/workflows/ansible-test-roles.yml
vendored
|
@ -51,6 +51,6 @@ jobs:
|
|||
run: |
|
||||
pip install ansible-lint docker flake8 molecule testinfra yamllint
|
||||
|
||||
- name: Run molecule default test scenario
|
||||
run: for d in roles/*/; do (cd "$d" && molecule --version && molecule test) done
|
||||
working-directory: ./ansible_collections/community/mysql
|
||||
# - name: Run molecule default test scenario
|
||||
# run: for d in roles/*/; do (cd "$d" && molecule --version && molecule test) done
|
||||
# working-directory: ./ansible_collections/community/mysql
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
destructive
|
||||
shippable/posix/group5
|
||||
skip/aix
|
||||
skip/osx
|
||||
skip/freebsd
|
|
@ -1,2 +0,0 @@
|
|||
dependencies:
|
||||
- setup_mysql_db
|
|
@ -1,6 +0,0 @@
|
|||
destructive
|
||||
shippable/posix/group1
|
||||
skip/aix
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
skip/rhel
|
|
@ -1,5 +0,0 @@
|
|||
---
|
||||
# defaults file for test_mysql_info
|
||||
db_name: data
|
||||
user_name: alice
|
||||
user_pass: alice
|
|
@ -1,190 +0,0 @@
|
|||
# Test code for mysql_info module
|
||||
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
###################
|
||||
# Prepare for tests
|
||||
#
|
||||
|
||||
# Create role for tests
|
||||
- name: mysql_info - create mysql user {{ user_name }}
|
||||
mysql_user:
|
||||
name: '{{ user_name }}'
|
||||
password: '{{ user_pass }}'
|
||||
state: present
|
||||
priv: '*.*:ALL'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
# Create default MySQL config file with credentials
|
||||
- name: mysql_info - create default config file
|
||||
template:
|
||||
src: my.cnf.j2
|
||||
dest: /root/.my.cnf
|
||||
mode: '0400'
|
||||
|
||||
# Create non-default MySQL config file with credentials
|
||||
- name: mysql_info - create non-default config file
|
||||
template:
|
||||
src: my.cnf.j2
|
||||
dest: /root/non-default_my.cnf
|
||||
mode: '0400'
|
||||
|
||||
###############
|
||||
# Do tests
|
||||
|
||||
# Access by default cred file
|
||||
- name: mysql_info - collect default cred file
|
||||
mysql_info:
|
||||
login_user: '{{ user_name }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
- result.settings != {}
|
||||
- result.global_status != {}
|
||||
- result.databases != {}
|
||||
- result.engines != {}
|
||||
- result.users != {}
|
||||
|
||||
# Access by non-default cred file
|
||||
- name: mysql_info - check non-default cred file
|
||||
mysql_info:
|
||||
login_user: '{{ user_name }}'
|
||||
config_file: /root/non-default_my.cnf
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
|
||||
# Remove cred files
|
||||
- name: mysql_info - remove cred files
|
||||
file:
|
||||
path: '{{ item }}'
|
||||
state: absent
|
||||
with_items:
|
||||
- /root/.my.cnf
|
||||
- /root/non-default_my.cnf
|
||||
|
||||
# Access with password
|
||||
- name: mysql_info - check access with password
|
||||
mysql_info:
|
||||
login_user: '{{ user_name }}'
|
||||
login_password: '{{ user_pass }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
|
||||
# Test excluding
|
||||
- name: Collect all info except settings and users
|
||||
mysql_info:
|
||||
login_user: '{{ user_name }}'
|
||||
login_password: '{{ user_pass }}'
|
||||
filter: '!settings,!users'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
- result.global_status != {}
|
||||
- result.databases != {}
|
||||
- result.engines != {}
|
||||
- result.settings is not defined
|
||||
- result.users is not defined
|
||||
|
||||
# Test including
|
||||
- name: Collect info only about version and databases
|
||||
mysql_info:
|
||||
login_user: '{{ user_name }}'
|
||||
login_password: '{{ user_pass }}'
|
||||
filter:
|
||||
- version
|
||||
- databases
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
- result.databases != {}
|
||||
- result.engines is not defined
|
||||
- result.settings is not defined
|
||||
- result.global_status is not defined
|
||||
- result.users is not defined
|
||||
|
||||
# Test exclude_fields: db_size
|
||||
# 'unsupported' element is passed to check that an unsupported value
|
||||
# won't break anything (will be ignored regarding to the module's documentation).
|
||||
- name: Collect info about databases excluding their sizes
|
||||
mysql_info:
|
||||
login_user: '{{ user_name }}'
|
||||
login_password: '{{ user_pass }}'
|
||||
filter:
|
||||
- databases
|
||||
exclude_fields:
|
||||
- db_size
|
||||
- unsupported
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.databases != {}
|
||||
- result.databases.mysql == {}
|
||||
|
||||
########################################################
|
||||
# Issue #65727, empty databases must be in returned dict
|
||||
#
|
||||
- name: Create empty database acme
|
||||
mysql_db:
|
||||
login_user: '{{ user_name }}'
|
||||
login_password: '{{ user_pass }}'
|
||||
name: acme
|
||||
|
||||
- name: Collect info about databases
|
||||
mysql_info:
|
||||
login_user: '{{ user_name }}'
|
||||
login_password: '{{ user_pass }}'
|
||||
filter:
|
||||
- databases
|
||||
return_empty_dbs: true
|
||||
register: result
|
||||
|
||||
# Check acme is in returned dict
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.databases.acme.size == 0
|
||||
- result.databases.mysql != {}
|
||||
|
||||
- name: Collect info about databases excluding their sizes
|
||||
mysql_info:
|
||||
login_user: '{{ user_name }}'
|
||||
login_password: '{{ user_pass }}'
|
||||
filter:
|
||||
- databases
|
||||
exclude_fields:
|
||||
- db_size
|
||||
return_empty_dbs: true
|
||||
register: result
|
||||
|
||||
# Check acme is in returned dict
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.databases.acme == {}
|
||||
- result.databases.mysql == {}
|
||||
|
||||
- name: Remove acme database
|
||||
mysql_db:
|
||||
login_user: '{{ user_name }}'
|
||||
login_password: '{{ user_pass }}'
|
||||
name: acme
|
||||
state: absent
|
|
@ -1,3 +0,0 @@
|
|||
[client]
|
||||
user={{ user_name }}
|
||||
password={{ user_pass }}
|
|
@ -1,6 +0,0 @@
|
|||
destructive
|
||||
shippable/posix/group3
|
||||
skip/aix
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
skip/rhel
|
|
@ -1,2 +0,0 @@
|
|||
dependencies:
|
||||
- setup_mysql8
|
|
@ -1,5 +0,0 @@
|
|||
# mysql_query module initial CI tests
|
||||
- import_tasks: mysql_query_initial.yml
|
||||
when:
|
||||
- ansible_distribution == 'CentOS'
|
||||
- ansible_distribution_major_version >= '7'
|
|
@ -1,5 +0,0 @@
|
|||
destructive
|
||||
shippable/posix/group1
|
||||
skip/aix
|
||||
skip/osx
|
||||
skip/freebsd
|
|
@ -1,78 +0,0 @@
|
|||
---
|
||||
|
||||
- name: Issue test setup - drop database
|
||||
mysql_db:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
loop:
|
||||
- foo
|
||||
- bar
|
||||
|
||||
- name: Issue test setup - create database
|
||||
mysql_db:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
loop:
|
||||
- foo
|
||||
- bar
|
||||
|
||||
- name: Copy SQL scripts to remote
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ remote_tmp_dir }}/{{ item | basename }}"
|
||||
with_items:
|
||||
- create-function.sql
|
||||
- create-procedure.sql
|
||||
|
||||
- name: Create function for test
|
||||
shell: "mysql < {{ remote_tmp_dir }}/create-function.sql"
|
||||
|
||||
- name: Create procedure for test
|
||||
shell: "mysql < {{ remote_tmp_dir }}/create-procedure.sql"
|
||||
|
||||
- name: Create user with FUNCTION and PROCEDURE privileges
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
state: present
|
||||
priv: 'FUNCTION foo.function:EXECUTE/foo.*:SELECT/PROCEDURE bar.procedure:EXECUTE'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: Assert Create user with FUNCTION and PROCEDURE privileges
|
||||
assert:
|
||||
that:
|
||||
- result is success
|
||||
- result is changed
|
||||
|
||||
- name: Create user with FUNCTION and PROCEDURE privileges - Idempotent check
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
state: present
|
||||
priv: 'FUNCTION foo.function:EXECUTE/foo.*:SELECT/PROCEDURE bar.procedure:EXECUTE'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: Assert Create user with FUNCTION and PROCEDURE privileges
|
||||
assert:
|
||||
that:
|
||||
- result is success
|
||||
- result is not changed
|
||||
|
||||
- name: Remove user
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: Issue test teardown - cleanup databases
|
||||
mysql_db:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
loop:
|
||||
- foo
|
||||
- bar
|
|
@ -1,27 +0,0 @@
|
|||
---
|
||||
|
||||
- name: Set root password
|
||||
mysql_user:
|
||||
name: root
|
||||
password: '{{ root_password }}'
|
||||
login_user: root
|
||||
login_password: '{{ root_password }}'
|
||||
check_implicit_admin: yes
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert root password is changed
|
||||
assert: { that: "result.changed == true" }
|
||||
|
||||
- name: Set root password again
|
||||
mysql_user:
|
||||
name: root
|
||||
password: '{{ root_password }}'
|
||||
login_user: root
|
||||
login_password: '{{ root_password }}'
|
||||
check_implicit_admin: yes
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: Assert root password is not changed
|
||||
assert: { that: "result.changed == false" }
|
|
@ -1,222 +0,0 @@
|
|||
# test code for the mysql_user module
|
||||
# (c) 2014, Wayne Rosario <wrosario@ansible.com>
|
||||
|
||||
# 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 dof 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ============================================================
|
||||
# create mysql user and verify user is added to mysql database
|
||||
#
|
||||
- include: create_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }}
|
||||
|
||||
- include: resource_limits.yml
|
||||
|
||||
- include: assert_user.yml user_name={{user_name_1}}
|
||||
|
||||
- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }}
|
||||
|
||||
- include: assert_no_user.yml user_name={{user_name_1}}
|
||||
|
||||
# ============================================================
|
||||
# Create mysql user that already exist on mysql database
|
||||
#
|
||||
- include: create_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }}
|
||||
|
||||
- name: create mysql user that already exist (expect changed=false)
|
||||
mysql_user:
|
||||
name: '{{user_name_1}}'
|
||||
password: '{{user_password_1}}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message mysql user was not created
|
||||
assert: { that: "result.changed == false" }
|
||||
|
||||
# ============================================================
|
||||
# remove mysql user and verify user is removed from mysql database
|
||||
#
|
||||
- name: remove mysql user state=absent (expect changed=true)
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message mysql user was removed
|
||||
assert: { that: "result.changed == true" }
|
||||
|
||||
- include: assert_no_user.yml user_name={{user_name_1}}
|
||||
|
||||
# ============================================================
|
||||
# remove mysql user that does not exist on mysql database
|
||||
#
|
||||
- name: remove mysql user that does not exist state=absent (expect changed=false)
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message mysql user that does not exist
|
||||
assert: { that: "result.changed == false" }
|
||||
|
||||
- include: assert_no_user.yml user_name={{user_name_1}}
|
||||
|
||||
# ============================================================
|
||||
# Create user with no privileges and verify default privileges are assign
|
||||
#
|
||||
- name: create user with select privilege state=present (expect changed=true)
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- include: assert_user.yml user_name={{user_name_1}} priv=USAGE
|
||||
|
||||
- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }}
|
||||
|
||||
- include: assert_no_user.yml user_name={{user_name_1}}
|
||||
|
||||
# ============================================================
|
||||
# Create user with select privileges and verify select privileges are assign
|
||||
#
|
||||
- name: create user with select privilege state=present (expect changed=true)
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
state: present
|
||||
priv: '*.*:SELECT'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- include: assert_user.yml user_name={{user_name_2}} priv=SELECT
|
||||
|
||||
- include: remove_user.yml user_name={{user_name_2}} user_password={{ user_password_2 }}
|
||||
|
||||
- include: assert_no_user.yml user_name={{user_name_2}}
|
||||
|
||||
# ============================================================
|
||||
# Assert user has access to multiple databases
|
||||
#
|
||||
- name: give users access to multiple databases
|
||||
mysql_user:
|
||||
name: '{{ item[0] }}'
|
||||
priv: '{{ item[1] }}.*:ALL'
|
||||
append_privs: yes
|
||||
password: '{{ user_password_1 }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
with_nested:
|
||||
- [ '{{ user_name_1 }}', '{{ user_name_2 }}']
|
||||
- "{{db_names}}"
|
||||
|
||||
- name: show grants access for user1 on multiple database
|
||||
command: mysql "-e SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost';"
|
||||
register: result
|
||||
|
||||
- name: assert grant access for user1 on multiple database
|
||||
assert: { that: "'{{ item }}' in result.stdout" }
|
||||
with_items: "{{db_names}}"
|
||||
|
||||
- name: show grants access for user2 on multiple database
|
||||
command: mysql "-e SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost';"
|
||||
register: result
|
||||
|
||||
- name: assert grant access for user2 on multiple database
|
||||
assert: { that: "'{{ item }}' in result.stdout" }
|
||||
with_items: "{{db_names}}"
|
||||
|
||||
- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }}
|
||||
|
||||
- include: remove_user.yml user_name={{user_name_2}} user_password={{ user_password_1 }}
|
||||
|
||||
- name: give user access to database via wildcard
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
priv: '%db.*:SELECT'
|
||||
append_privs: yes
|
||||
password: '{{ user_password_1 }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: show grants access for user1 on multiple database
|
||||
command: mysql "-e SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost';"
|
||||
register: result
|
||||
|
||||
- name: assert grant access for user1 on multiple database
|
||||
assert:
|
||||
that:
|
||||
- "'%db' in result.stdout"
|
||||
- "'SELECT' in result.stdout"
|
||||
|
||||
- name: change user access to database via wildcard
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
priv: '%db.*:INSERT'
|
||||
append_privs: yes
|
||||
password: '{{ user_password_1 }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: show grants access for user1 on multiple database
|
||||
command: mysql "-e SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost';"
|
||||
register: result
|
||||
|
||||
- name: assert grant access for user1 on multiple database
|
||||
assert:
|
||||
that:
|
||||
- "'%db' in result.stdout"
|
||||
- "'INSERT' in result.stdout"
|
||||
|
||||
- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }}
|
||||
|
||||
# ============================================================
|
||||
# Update user password for a user.
|
||||
# Assert the user password is updated and old password can no longer be used.
|
||||
#
|
||||
#- include: user_password_update_test.yml
|
||||
|
||||
# ============================================================
|
||||
# Assert create user with SELECT privileges, attempt to create database and update privileges to create database
|
||||
#
|
||||
- include: test_privs.yml current_privilege=SELECT current_append_privs=no
|
||||
|
||||
# ============================================================
|
||||
# Assert creating user with SELECT privileges, attempt to create database and append privileges to create database
|
||||
#
|
||||
- include: test_privs.yml current_privilege=DROP current_append_privs=yes
|
||||
|
||||
# ============================================================
|
||||
# Assert create user with SELECT privileges, attempt to create database and update privileges to create database
|
||||
#
|
||||
- include: test_privs.yml current_privilege='UPDATE,ALTER' current_append_privs=no
|
||||
|
||||
# ============================================================
|
||||
# Assert creating user with SELECT privileges, attempt to create database and append privileges to create database
|
||||
#
|
||||
- include: test_privs.yml current_privilege='INSERT,DELETE' current_append_privs=yes
|
||||
|
||||
# Tests for the priv parameter with dict value (https://github.com/ansible/ansible/issues/57533)
|
||||
- include: test_priv_dict.yml
|
||||
|
||||
- import_tasks: issue-29511.yaml
|
||||
tags:
|
||||
- issue-29511
|
||||
|
||||
- import_tasks: issue-64560.yaml
|
||||
tags:
|
||||
- issue-64560
|
|
@ -1,59 +0,0 @@
|
|||
# test code to remove mysql user
|
||||
# (c) 2014, Wayne Rosario <wrosario@ansible.com>
|
||||
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ============================================================
|
||||
- name: remove mysql user {{user_name}}
|
||||
mysql_user:
|
||||
name: '{{user_name}}'
|
||||
password: '{{user_password}}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message mysql user was removed
|
||||
assert: { that: "result.changed == true" }
|
||||
|
||||
# ============================================================
|
||||
- name: create blank mysql user to be removed later
|
||||
mysql_user:
|
||||
name: ""
|
||||
state: present
|
||||
password: 'KJFDY&D*Sfuydsgf'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: remove blank mysql user with hosts=all (expect changed)
|
||||
mysql_user:
|
||||
user: ""
|
||||
host_all: true
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert changed is true for removing all blank users
|
||||
assert: { that: "result.changed == true" }
|
||||
|
||||
- name: remove blank mysql user with hosts=all (expect ok)
|
||||
mysql_user:
|
||||
user: ""
|
||||
host_all: true
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert changed is true for removing all blank users
|
||||
assert: { that: "result.changed == false" }
|
|
@ -1,112 +0,0 @@
|
|||
# test code for resource_limits parameter
|
||||
|
||||
- block:
|
||||
|
||||
- name: Drop mysql user {{ user_name_1 }} if exists
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: Create mysql user {{ user_name_1 }} with resource limits in check_mode
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
resource_limits:
|
||||
MAX_QUERIES_PER_HOUR: 10
|
||||
MAX_CONNECTIONS_PER_HOUR: 5
|
||||
check_mode: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: Create mysql user {{ user_name_1 }} with resource limits in actual mode
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
resource_limits:
|
||||
MAX_QUERIES_PER_HOUR: 10
|
||||
MAX_CONNECTIONS_PER_HOUR: 5
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: Check
|
||||
mysql_query:
|
||||
query: >
|
||||
SELECT User FROM mysql.user WHERE User = '{{ user_name_1 }}' AND Host = 'localhost'
|
||||
AND max_questions = 10 AND max_connections = 5
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.rowcount[0] == 1
|
||||
|
||||
- name: Try to set the same limits again in check mode
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
resource_limits:
|
||||
MAX_QUERIES_PER_HOUR: 10
|
||||
MAX_CONNECTIONS_PER_HOUR: 5
|
||||
check_mode: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
|
||||
- name: Try to set the same limits again in actual mode
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
resource_limits:
|
||||
MAX_QUERIES_PER_HOUR: 10
|
||||
MAX_CONNECTIONS_PER_HOUR: 5
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
|
||||
- name: Change limits
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
resource_limits:
|
||||
MAX_QUERIES_PER_HOUR: 5
|
||||
MAX_CONNECTIONS_PER_HOUR: 5
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: Check
|
||||
mysql_query:
|
||||
query: >
|
||||
SELECT User FROM mysql.user WHERE User = '{{ user_name_1 }}' AND Host = 'localhost'
|
||||
AND max_questions = 5 AND max_connections = 5
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.rowcount[0] == 1
|
||||
|
||||
when: (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version >= '18') or (ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '8')
|
|
@ -1,46 +0,0 @@
|
|||
# Tests for priv parameter value passed as a dict
|
||||
- name: Create test databases
|
||||
mysql_db:
|
||||
name: '{{ item }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
loop:
|
||||
- data1
|
||||
- data2
|
||||
|
||||
- name: Create user with privileges
|
||||
mysql_user:
|
||||
name: '{{ user_name_3 }}'
|
||||
password: '{{ user_password_3 }}'
|
||||
priv:
|
||||
"data1.*": "SELECT"
|
||||
"data2.*": "SELECT"
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: Run command to show privileges for user (expect privileges in stdout)
|
||||
command: mysql "-e SHOW GRANTS FOR '{{ user_name_3 }}'@'localhost';"
|
||||
register: result
|
||||
|
||||
- name: Assert user has giving privileges
|
||||
assert:
|
||||
that:
|
||||
- "'GRANT SELECT ON `data1`.*' in result.stdout"
|
||||
- "'GRANT SELECT ON `data2`.*' in result.stdout"
|
||||
|
||||
##########
|
||||
# Clean up
|
||||
- name: Drop test databases
|
||||
mysql_db:
|
||||
name: '{{ item }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
loop:
|
||||
- data1
|
||||
- data2
|
||||
|
||||
- name: Drop test user
|
||||
mysql_user:
|
||||
name: '{{ user_name_3 }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
|
@ -1,155 +0,0 @@
|
|||
# test code for privileges for mysql_user module
|
||||
# (c) 2014, Wayne Rosario <wrosario@ansible.com>
|
||||
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ============================================================
|
||||
- name: create user with basic select privileges
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
priv: '*.*:SELECT'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
when: current_append_privs == "yes"
|
||||
|
||||
- include: assert_user.yml user_name={{user_name_2}} priv='SELECT'
|
||||
when: current_append_privs == "yes"
|
||||
|
||||
- name: create user with current privileges (expect changed=true)
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
priv: '*.*:{{current_privilege}}'
|
||||
append_privs: '{{current_append_privs}}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message for current privileges
|
||||
assert: { that: "result.changed == true" }
|
||||
|
||||
- name: run command to show privileges for user (expect privileges in stdout)
|
||||
command: mysql "-e SHOW GRANTS FOR '{{user_name_2}}'@'localhost';"
|
||||
register: result
|
||||
|
||||
- name: assert user has correct privileges
|
||||
assert: { that: "'GRANT {{current_privilege | replace(',', ', ')}} ON *.*' in result.stdout" }
|
||||
when: current_append_privs == "no"
|
||||
|
||||
- name: assert user has correct privileges
|
||||
assert: { that: "'GRANT SELECT, {{current_privilege | replace(',', ', ')}} ON *.*' in result.stdout" }
|
||||
when: current_append_privs == "yes"
|
||||
|
||||
- name: create database using user current privileges
|
||||
mysql_db:
|
||||
name: '{{ db_name }}'
|
||||
state: present
|
||||
login_user: '{{ user_name_2 }}'
|
||||
login_password: '{{ user_password_2 }}'
|
||||
ignore_errors: true
|
||||
|
||||
- name: run command to test that database was not created
|
||||
command: mysql "-e show databases like '{{ db_name }}';"
|
||||
register: result
|
||||
|
||||
- name: assert database was not created
|
||||
assert: { that: "'{{ db_name }}' not in result.stdout" }
|
||||
|
||||
# ============================================================
|
||||
- name: Add privs to a specific table (expect changed)
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
priv: 'jmainguy.jmainguy:ALL'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: Assert that priv changed
|
||||
assert: { that: "result.changed == true" }
|
||||
|
||||
- name: Add privs to a specific table (expect ok)
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
priv: 'jmainguy.jmainguy:ALL'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: Assert that priv did not change
|
||||
assert: { that: "result.changed == false" }
|
||||
|
||||
# ============================================================
|
||||
- name: update user with all privileges
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
priv: '*.*:ALL'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- include: assert_user.yml user_name={{user_name_2}} priv='ALL PRIVILEGES'
|
||||
|
||||
- name: create database using user
|
||||
mysql_db:
|
||||
name: '{{ db_name }}'
|
||||
state: present
|
||||
login_user: '{{ user_name_2 }}'
|
||||
login_password: '{{ user_password_2 }}'
|
||||
|
||||
- name: run command to test database was created using user new privileges
|
||||
command: mysql "-e SHOW CREATE DATABASE {{ db_name }};"
|
||||
|
||||
- name: drop database using user
|
||||
mysql_db:
|
||||
name: '{{ db_name }}'
|
||||
state: absent
|
||||
login_user: '{{ user_name_2 }}'
|
||||
login_password: '{{ user_password_2 }}'
|
||||
|
||||
# ============================================================
|
||||
- name: update user with a long privileges list (mysql has a special multiline grant output)
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
priv: '*.*:CREATE USER,FILE,PROCESS,RELOAD,REPLICATION CLIENT,REPLICATION SLAVE,SHOW DATABASES,SHUTDOWN,SUPER,CREATE,DROP,EVENT,LOCK TABLES,INSERT,UPDATE,DELETE,SELECT,SHOW VIEW,GRANT'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: Assert that priv changed
|
||||
assert: { that: "result.changed == true" }
|
||||
|
||||
- name: Test idempotency (expect ok)
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
priv: '*.*:CREATE USER,FILE,PROCESS,RELOAD,REPLICATION CLIENT,REPLICATION SLAVE,SHOW DATABASES,SHUTDOWN,SUPER,CREATE,DROP,EVENT,LOCK TABLES,INSERT,UPDATE,DELETE,SELECT,SHOW VIEW,GRANT'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: Assert that priv did not change
|
||||
assert: { that: "result.changed == false" }
|
||||
|
||||
- name: remove username
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
|
@ -1,155 +0,0 @@
|
|||
# test code update password for the mysql_user module
|
||||
# (c) 2014, Wayne Rosario <wrosario@ansible.com>
|
||||
|
||||
# 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 dof 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ============================================================
|
||||
# Update user password for a user.
|
||||
# Assert the user password is updated and old password can no longer be used.
|
||||
#
|
||||
- name: create user1 state=present with a password
|
||||
mysql_user:
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
priv: '*.*:ALL'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: create user2 state=present with a password
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
priv: '*.*:ALL'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: store user2 grants with old password (mysql 5.7.6 and newer)
|
||||
command: mysql "-e SHOW CREATE USER '{{ user_name_2 }}'@'localhost';"
|
||||
register: user_password_old_create
|
||||
ignore_errors: yes
|
||||
|
||||
- name: store user2 grants with old password (mysql 5.7.5 and older)
|
||||
command: mysql "-e SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost';"
|
||||
register: user_password_old
|
||||
when: user_password_old_create is failed
|
||||
|
||||
- name: update user2 state=present with same password (expect changed=false)
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_2 }}'
|
||||
priv: '*.*:ALL'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output user2 was not updated
|
||||
assert: { that: "result.changed == false" }
|
||||
|
||||
- include: assert_user.yml user_name={{user_name_2}} priv='ALL PRIVILEGES'
|
||||
|
||||
- name: update user2 state=present with a new password (expect changed=true)
|
||||
mysql_user:
|
||||
name: '{{ user_name_2 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- include: assert_user.yml user_name={{user_name_2}} priv='ALL PRIVILEGES'
|
||||
|
||||
- name: store user2 grants with old password (mysql 5.7.6 and newer)
|
||||
command: mysql "-e SHOW CREATE USER '{{ user_name_2 }}'@'localhost';"
|
||||
register: user_password_new_create
|
||||
ignore_errors: yes
|
||||
|
||||
- name: store user2 grants with new password
|
||||
command: mysql "-e SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost';"
|
||||
register: user_password_new
|
||||
when: user_password_new_create is failed
|
||||
|
||||
- name: assert output message password was update for user2 (mysql 5.7.6 and newer)
|
||||
assert: { that: "user_password_old_create.stdout != user_password_new_create.stdout" }
|
||||
when: user_password_new_create is not failed
|
||||
|
||||
- name: assert output message password was update for user2 (mysql 5.7.5 and older)
|
||||
assert: { that: "user_password_old.stdout != user_password_new.stdout" }
|
||||
when: user_password_new_create is failed
|
||||
|
||||
- name: create database using user2 and old password
|
||||
mysql_db:
|
||||
name: '{{ db_name }}'
|
||||
state: present
|
||||
login_user: '{{ user_name_2 }}'
|
||||
login_password: '{{ user_password_2 }}'
|
||||
ignore_errors: true
|
||||
register: result
|
||||
|
||||
- debug: var=result.msg
|
||||
- name: assert output message that database not create with old password
|
||||
assert:
|
||||
that:
|
||||
- "result.failed == true"
|
||||
|
||||
- name: create database using user2 and new password
|
||||
mysql_db:
|
||||
name: '{{ db_name }}'
|
||||
state: present
|
||||
login_user: '{{ user_name_2 }}'
|
||||
login_password: '{{ user_password_1 }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message that database is created with new password
|
||||
assert: { that: "result.changed == true" }
|
||||
|
||||
- name: remove database
|
||||
mysql_db:
|
||||
name: '{{ db_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }}
|
||||
|
||||
- include: remove_user.yml user_name={{user_name_2}} user_password={{ user_password_1 }}
|
||||
|
||||
- name: Create user with Fdt8fd^34ds using hash. (expect changed=true)
|
||||
mysql_user:
|
||||
name: jmainguy
|
||||
password: '*0cb5b86f23fdc24db19a29b8854eb860cbc47793'
|
||||
encrypted: yes
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: encrypt_result
|
||||
|
||||
- name: Check that the module made a change
|
||||
assert:
|
||||
that:
|
||||
- "encrypt_result.changed == True"
|
||||
|
||||
- name: See if the password needs to be updated. (expect changed=false)
|
||||
mysql_user:
|
||||
name: jmainguy
|
||||
password: 'Fdt8fd^34ds'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: plain_result
|
||||
|
||||
- name: Check that the module did not change the password
|
||||
assert:
|
||||
that:
|
||||
- "plain_result.changed == False"
|
||||
|
||||
- name: Remove user (cleanup)
|
||||
mysql_user:
|
||||
name: jmainguy
|
||||
state: absent
|
|
@ -1,6 +0,0 @@
|
|||
destructive
|
||||
shippable/posix/group3
|
||||
skip/aix
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
skip/rhel
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
# defaults file for test_mysql_variables
|
||||
user: 'user1'
|
||||
password: 'khH&DYigjg1#'
|
|
@ -1,2 +0,0 @@
|
|||
dependencies:
|
||||
- setup_mysql8
|
|
@ -1,2 +0,0 @@
|
|||
- import_tasks: mysql_variables.yml
|
||||
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7'
|
|
@ -1,412 +0,0 @@
|
|||
# test code for the mysql_variables module
|
||||
# (c) 2014, Wayne Rosario <wrosario@ansible.com>
|
||||
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ============================================================
|
||||
# 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 }}'
|
||||
|
||||
#=========================================
|
||||
# Check mode 'persist' and 'persist_only':
|
||||
#
|
||||
- name: update mysql variable value (expect changed=true) in persist mode
|
||||
mysql_variables:
|
||||
variable: '{{ set_name }}'
|
||||
value: '{{ set_value }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
login_user: root
|
||||
login_password: '{{ root_pass }}'
|
||||
mode: persist
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.queries == ["SET PERSIST `{{ set_name }}` = {{ set_value }}"]
|
||||
|
||||
- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}'
|
||||
|
||||
- name: try to update mysql variable value (expect changed=false) in persist mode again
|
||||
mysql_variables:
|
||||
variable: '{{ set_name }}'
|
||||
value: '{{ set_value }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
login_user: root
|
||||
login_password: '{{ root_pass }}'
|
||||
mode: persist
|
||||
register: result
|
||||
|
||||
- include: assert_var.yml changed=false output={{result}} var_name={{set_name}} var_value='{{set_value}}'
|
||||
|
||||
- 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 }}'
|
||||
mode: persist
|
||||
|
||||
- name: update mysql variable value (expect changed=true) in persist_only mode
|
||||
mysql_variables:
|
||||
variable: '{{ set_name }}'
|
||||
value: '{{ set_value }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
login_user: root
|
||||
login_password: '{{ root_pass }}'
|
||||
mode: persist_only
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["SET PERSIST_ONLY `{{ set_name }}` = {{ set_value }}"]
|
||||
|
||||
- name: try to update mysql variable value (expect changed=false) in persist_only mode again
|
||||
mysql_variables:
|
||||
variable: '{{ set_name }}'
|
||||
value: '{{ set_value }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
login_user: root
|
||||
login_password: '{{ root_pass }}'
|
||||
mode: persist_only
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
|
||||
- set_fact:
|
||||
set_name: max_connections
|
||||
set_value: 105
|
||||
def_val: 151
|
||||
|
||||
- name: update mysql variable value (expect changed=true) in persist_only mode
|
||||
mysql_variables:
|
||||
variable: '{{ set_name }}'
|
||||
value: '{{ set_value }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
login_user: root
|
||||
login_password: '{{ root_pass }}'
|
||||
mode: persist_only
|
||||
register: result
|
||||
|
||||
- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{def_val}}'
|
||||
|
||||
# Bugfix of https://github.com/ansible/ansible/issues/54239
|
||||
- name: set variable containing dot
|
||||
mysql_variables:
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
login_user: root
|
||||
login_password: '{{ root_pass }}'
|
||||
variable: validate_password.policy
|
||||
value: LOW
|
||||
mode: persist_only
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["SET PERSIST_ONLY `validate_password`.`policy` = LOW"]
|
|
@ -1,21 +0,0 @@
|
|||
repo_link: https://repo.mysql.com/mysql80-community-release-el{{ ansible_facts.distribution_major_version }}.rpm
|
||||
my_cnf: /etc/my.cnf
|
||||
|
||||
mysql_data_dirs:
|
||||
- /var/lib/mysql
|
||||
- /usr/mysql
|
||||
|
||||
mysql_support_packages:
|
||||
- MySQL-python
|
||||
|
||||
mysql_server_packages:
|
||||
- mysql-community-server
|
||||
|
||||
mysql_cleanup_packages:
|
||||
- mysql-community-client
|
||||
- mysql-community-common
|
||||
- mysql-community-libs
|
||||
- mysql-community-libs-compat
|
||||
- mysql-community-server
|
||||
- mysql80-community-release
|
||||
- python3-PyMySQL
|
|
@ -1,7 +0,0 @@
|
|||
[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
|
|
@ -1,29 +0,0 @@
|
|||
- name: stop mysql service
|
||||
service:
|
||||
name: mysqld
|
||||
state: stopped
|
||||
listen: cleanup mysql8
|
||||
|
||||
- name: remove repo
|
||||
# yum:
|
||||
# name: mysql80-community-release
|
||||
# state: absent
|
||||
# Work around for a bug in the dnf module. Use the module once that gets fixed.
|
||||
# https://github.com/ansible/ansible/issues/64294
|
||||
command: "{{ ansible_facts.pkg_mgr}} -y erase mysql80-community-release"
|
||||
args:
|
||||
warn: no
|
||||
listen: cleanup mysql8
|
||||
|
||||
- name: remove mysql packages
|
||||
yum:
|
||||
name: '{{ mysql_support_packages | union(mysql_server_packages) | union(mysql_cleanup_packages) }}'
|
||||
state: absent
|
||||
listen: cleanup mysql8
|
||||
|
||||
- name: remove mysql data
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop: "{{ mysql_data_dirs }}"
|
||||
listen: cleanup mysql8
|
|
@ -1,18 +0,0 @@
|
|||
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Setup MySQL 8:
|
||||
- name: Include distribution specific variables
|
||||
include_vars: "{{ lookup('first_found', params) }}"
|
||||
vars:
|
||||
params:
|
||||
files:
|
||||
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml'
|
||||
- '{{ ansible_facts.os_family }}.yml'
|
||||
- 'default.yml'
|
||||
paths: vars
|
||||
|
||||
- import_tasks: setup_mysql8.yml
|
||||
when:
|
||||
- ansible_facts.distribution == 'CentOS'
|
||||
- ansible_facts.distribution_major_version is version_compare('7', '>=')
|
|
@ -1,71 +0,0 @@
|
|||
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
- name: Install PyMySQL package via pip
|
||||
pip:
|
||||
name: PyMySQL
|
||||
state: present
|
||||
|
||||
- name: Install MySQL repo
|
||||
yum:
|
||||
name: '{{ repo_link }}'
|
||||
notify: cleanup mysql8
|
||||
|
||||
# These packages come from AppStream in RHEL 8, so they need to be done in a separate task
|
||||
- name: Install MySQL support packages
|
||||
yum:
|
||||
name: "{{ mysql_support_packages }}"
|
||||
notify: cleanup mysql8
|
||||
|
||||
- name: Install MySQL community server
|
||||
yum:
|
||||
name: '{{ mysql_server_packages }}'
|
||||
disablerepo: '{{ mysql_disablerepo | default(omit) }}'
|
||||
notify: cleanup mysql8
|
||||
|
||||
- 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
|
|
@ -1,4 +0,0 @@
|
|||
mysql_support_packages:
|
||||
- python3-PyMySQL
|
||||
|
||||
mysql_disablerepo: AppStream
|
|
@ -1,3 +0,0 @@
|
|||
mysql_data_dirs:
|
||||
- /var/lib/mysql
|
||||
- /usr/share/mysql
|
|
@ -1,4 +0,0 @@
|
|||
mysql_support_packages:
|
||||
- python3-PyMySQL
|
||||
|
||||
mysql_disablerepo: rhel-8-for-x86_64-appstream-rpms
|
|
@ -1,18 +0,0 @@
|
|||
mysql_service: mysqld
|
||||
|
||||
mysql_packages:
|
||||
- mysql-server
|
||||
- MySQL-python
|
||||
- bzip2
|
||||
|
||||
mysql_cleanup_packages:
|
||||
- mysql-community-client
|
||||
- mysql-community-common
|
||||
- mysql-community-libs
|
||||
- mysql-community-libs-compat
|
||||
- mysql-community-server
|
||||
- mysql80-community-release
|
||||
|
||||
mysql_data_dirs:
|
||||
- /var/lib/mysql
|
||||
- /usr/mysql
|
|
@ -1,25 +0,0 @@
|
|||
- name: stop mysql service
|
||||
service:
|
||||
name: "{{ mysql_service }}"
|
||||
state: stopped
|
||||
listen: cleanup mysql
|
||||
|
||||
- name: remove mysql packages
|
||||
action: '{{ ansible_facts.pkg_mgr }}'
|
||||
args:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
loop: "{{ mysql_packages | union(mysql_cleanup_packages) }}"
|
||||
listen: cleanup mysql
|
||||
|
||||
- name: remove mysql data
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop: "{{ mysql_data_dirs }}"
|
||||
listen: cleanup mysql
|
||||
|
||||
- name: remove pip packages
|
||||
pip:
|
||||
name: mysql-python
|
||||
state: absent
|
|
@ -1,2 +0,0 @@
|
|||
dependencies:
|
||||
- setup_pkg_mgr
|
|
@ -1,112 +0,0 @@
|
|||
# setup code for the mysql_db module
|
||||
# (c) 2014, Wayne Rosario <wrosario@ansible.com>
|
||||
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ============================================================
|
||||
- name: python 2
|
||||
set_fact:
|
||||
python_suffix: ""
|
||||
when: ansible_python_version is version('3', '<')
|
||||
|
||||
- name: python 3
|
||||
set_fact:
|
||||
python_suffix: "-py3"
|
||||
when: ansible_python_version is version('3', '>=')
|
||||
|
||||
- name: Include distribution specific variables
|
||||
include_vars: "{{ lookup('first_found', params) }}"
|
||||
vars:
|
||||
params:
|
||||
files:
|
||||
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}{{ python_suffix }}.yml'
|
||||
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml'
|
||||
- '{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}{{ python_suffix }}.yml'
|
||||
- '{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml'
|
||||
- '{{ ansible_facts.distribution }}{{ python_suffix }}.yml'
|
||||
- '{{ ansible_facts.os_family }}{{ python_suffix }}.yml'
|
||||
- 'default{{ python_suffix }}.yml'
|
||||
paths: "{{ role_path }}/vars"
|
||||
|
||||
- name: install mysqldb_test rpm dependencies
|
||||
yum:
|
||||
name: "{{ mysql_packages }}"
|
||||
state: latest
|
||||
when: ansible_facts.pkg_mgr == 'yum'
|
||||
notify: cleanup mysql
|
||||
|
||||
- name: install mysqldb_test rpm dependencies
|
||||
dnf:
|
||||
name: '{{ mysql_packages }}'
|
||||
state: latest
|
||||
install_weak_deps: False # mariadb-server has a weak dep on python2 which break Python 3 test environments
|
||||
when: ansible_facts.pkg_mgr == 'dnf'
|
||||
notify: cleanup mysql
|
||||
|
||||
- name: install mysqldb_test debian dependencies
|
||||
apt:
|
||||
name: "{{ mysql_packages }}"
|
||||
state: latest
|
||||
when: ansible_facts.pkg_mgr == 'apt'
|
||||
notify: cleanup mysql
|
||||
|
||||
- name: install mysqldb_test opensuse dependencies
|
||||
zypper:
|
||||
name: "{{ mysql_packages }}"
|
||||
state: latest
|
||||
when: ansible_facts.pkg_mgr in ['zypper', 'community.general.zypper']
|
||||
notify: cleanup mysql
|
||||
|
||||
- name: install mysqldb_test FreeBSD dependencies
|
||||
package:
|
||||
name: "{{ mysql_packages }}"
|
||||
state: present
|
||||
when: ansible_os_family == "FreeBSD"
|
||||
notify: cleanup mysql
|
||||
|
||||
- name: install mysql-python package via pip (FreeBSD)
|
||||
pip:
|
||||
name: mysql-python
|
||||
state: present
|
||||
when: ansible_os_family == "FreeBSD"
|
||||
notify:
|
||||
- cleanup mysql
|
||||
- remove pip packages
|
||||
|
||||
- name: enable mysql-server service (FreeBSD)
|
||||
lineinfile:
|
||||
path: /etc/rc.conf
|
||||
line: 'mysql_server_enable="YES"'
|
||||
when: ansible_os_family == "FreeBSD"
|
||||
|
||||
- name: apply work-around for OverlayFS issue
|
||||
# https://github.com/docker/for-linux/issues/72#issuecomment-319904698
|
||||
command: find {{ mysql_data_dirs[0] }} -type f -exec touch {} ;
|
||||
# find will fail if mysql has never been started, as the directory won't exist
|
||||
ignore_errors: yes
|
||||
|
||||
- name: restart mysql_db service
|
||||
service:
|
||||
name: "{{ mysql_service }}"
|
||||
state: restarted
|
||||
|
||||
- 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"] }}'
|
|
@ -1,16 +0,0 @@
|
|||
mysql_service: 'mysql'
|
||||
|
||||
mysql_packages:
|
||||
- mysql-server
|
||||
- python-mysqldb
|
||||
- bzip2
|
||||
|
||||
mysql_cleanup_packages:
|
||||
- mysql-client*
|
||||
- mysql-server*
|
||||
- mysql-common
|
||||
- mysql-sandbox
|
||||
|
||||
mysql_data_dirs:
|
||||
- /var/lib/mysql
|
||||
- /usr/share/mysql
|
|
@ -1,6 +0,0 @@
|
|||
mysql_service: 'mariadb'
|
||||
|
||||
mysql_packages:
|
||||
- mariadb-server
|
||||
- python3-PyMySQL
|
||||
- bzip2
|
|
@ -1,6 +0,0 @@
|
|||
mysql_service: 'mariadb'
|
||||
|
||||
mysql_packages:
|
||||
- mariadb-server
|
||||
- python-PyMySQL
|
||||
- bzip2
|
|
@ -1,5 +0,0 @@
|
|||
mysql_service: 'mysql-server'
|
||||
|
||||
mysql_packages:
|
||||
- mariadb101-server
|
||||
- py-pymysql
|
|
@ -1,6 +0,0 @@
|
|||
mysql_service: 'mariadb'
|
||||
|
||||
mysql_packages:
|
||||
- mariadb-server
|
||||
- MySQL-python
|
||||
- bzip2
|
|
@ -1,6 +0,0 @@
|
|||
mysql_service: 'mariadb'
|
||||
|
||||
mysql_packages:
|
||||
- mariadb-server
|
||||
- python3-PyMySQL
|
||||
- bzip2
|
|
@ -1,6 +0,0 @@
|
|||
mysql_service: 'mysqld'
|
||||
|
||||
mysql_packages:
|
||||
- mysql-server
|
||||
- MySQL-python
|
||||
- bzip2
|
|
@ -1,6 +0,0 @@
|
|||
mysql_service: 'mysql'
|
||||
|
||||
mysql_packages:
|
||||
- mariadb
|
||||
- python3-PyMySQL
|
||||
- bzip2
|
|
@ -1,6 +0,0 @@
|
|||
mysql_service: 'mysql'
|
||||
|
||||
mysql_packages:
|
||||
- mariadb
|
||||
- python-PyMySQL
|
||||
- bzip2
|
|
@ -1,16 +0,0 @@
|
|||
mysql_service: 'mysql'
|
||||
|
||||
mysql_packages:
|
||||
- mysql-server
|
||||
- python3-pymysql
|
||||
- bzip2
|
||||
|
||||
mysql_cleanup_packages:
|
||||
- mysql-client*
|
||||
- mysql-server*
|
||||
- mysql-common
|
||||
- mysql-sandbox
|
||||
|
||||
mysql_data_dirs:
|
||||
- /var/lib/mysql
|
||||
- /usr/share/mysql
|
|
@ -1,14 +0,0 @@
|
|||
# There is no MySQL 5.7 for RHEL 8. This will need to be retooled to use 8.0 for RHEL 8 or use the setup_mysql8 role for everything
|
||||
repo_link: https://repo.mysql.com/mysql57-community-release-el{{ ansible_facts.distribution_major_version }}.rpm
|
||||
repo_name: mysql-community
|
||||
mysql_package_name: mysql-community-server
|
||||
|
||||
master_port: 3306
|
||||
standby_port: 3307
|
||||
master_datadir: /var/lib/mysql_master
|
||||
master_cnf: /etc/my-1.cnf
|
||||
standby_cnf: /etc/my-2.cnf
|
||||
standby_datadir: /var/lib/mysql_standby
|
||||
standby_logdir: /var/log/mysql_standby
|
||||
default_logdir: /var/log/mysql
|
||||
mysqld_err_log: '{{ default_logdir }}/mysql-err.log'
|
|
@ -1,8 +0,0 @@
|
|||
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Setup MySQL master-standby replication into one container:
|
||||
- import_tasks: setup_mysql_cluster.yml
|
||||
when:
|
||||
- ansible_facts.distribution == 'CentOS'
|
||||
- ansible_facts.distribution_major_version is version('7', '==')
|
|
@ -1,65 +0,0 @@
|
|||
# We run two servers listening different ports
|
||||
# to be able to check replication (one server for master, another for standby).
|
||||
|
||||
- name: Install PyMySQL package via pip
|
||||
pip:
|
||||
name: PyMySQL
|
||||
state: present
|
||||
|
||||
- name: Install Repo
|
||||
yum:
|
||||
name: '{{ repo_link }}'
|
||||
|
||||
- name: Install MySQL community server
|
||||
yum:
|
||||
name: '{{ mysql_package_name }}'
|
||||
|
||||
- name: Create directories
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
owner: mysql
|
||||
group: mysql
|
||||
loop:
|
||||
- "{{ master_datadir }}"
|
||||
- "{{ standby_datadir }}"
|
||||
- "{{ standby_logdir }}"
|
||||
- "{{ default_logdir }}"
|
||||
|
||||
- name: Copy cnf templates
|
||||
template:
|
||||
src: '{{ item.conf_templ }}'
|
||||
dest: '{{ item.conf_dest }}'
|
||||
owner: mysql
|
||||
group: mysql
|
||||
force: yes
|
||||
loop:
|
||||
- { conf_templ: my-1.cnf.j2, conf_dest: '{{ master_cnf }}' }
|
||||
- { conf_templ: my-2.cnf.j2, conf_dest: '{{ standby_cnf }}' }
|
||||
|
||||
- name: Initialize DBs
|
||||
shell: 'mysqld --user=mysql --initialize-insecure --datadir={{ item }}'
|
||||
loop:
|
||||
- '{{ master_datadir }}'
|
||||
- '{{ standby_datadir }}'
|
||||
|
||||
- name: Start master services
|
||||
shell: 'mysqld --defaults-file={{ master_cnf }} --user=mysql --datadir={{ master_datadir }} --log-error={{ mysqld_err_log }} &'
|
||||
|
||||
- name: Start standby services
|
||||
shell: 'mysqld --defaults-file={{ standby_cnf }} --user=mysql --datadir={{ standby_datadir }} --log-error={{ mysqld_err_log }} &'
|
||||
|
||||
- name: Pause
|
||||
pause: seconds=3
|
||||
|
||||
########### For painful debug uncomment the lines below ##
|
||||
#- name: DEBUG Check log
|
||||
# shell: 'cat {{ mysqld_err_log }}'
|
||||
# ignore_errors: yes
|
||||
##########################################################
|
||||
|
||||
- name: Check connection to the master
|
||||
shell: 'echo "SHOW DATABASES;" | mysql -P {{ master_port }} -h 127.0.0.1'
|
||||
|
||||
- name: Check connection to the standby
|
||||
shell: "echo \"SHOW VARIABLES LIKE '%version%';\" | mysql -P {{ standby_port }} -h 127.0.0.1"
|
|
@ -1,11 +0,0 @@
|
|||
[mysqld]
|
||||
server_id = 1
|
||||
port = {{ master_port }}
|
||||
datadir = {{ master_datadir }}
|
||||
socket = {{ master_datadir }}/mysql.sock
|
||||
pid-file = {{ master_datadir }}/mysql.pid
|
||||
#mysqladmin = /usr/bin/mysqladmin
|
||||
log_bin = /var/log/mysql/mysql-bin.log
|
||||
sync_binlog = 1
|
||||
binlog-format = ROW
|
||||
innodb_flush_log_at_trx_commit = 1
|
|
@ -1,13 +0,0 @@
|
|||
[mysqld]
|
||||
server_id = 2
|
||||
port = {{ standby_port }}
|
||||
socket = /var/run/mysqld/mysqld_slave.sock
|
||||
pid-file = /var/run/mysqld/mysqld_slave.pid
|
||||
datadir = {{ standby_datadir }}
|
||||
log_bin = {{ standby_logdir }}/mysql-bin.log
|
||||
relay-log = {{ standby_logdir }}/relay-bin
|
||||
relay-log-index = {{ standby_logdir }}/relay-bin.index
|
||||
master-info-file = {{ standby_logdir }}/master.info
|
||||
relay-log-info-file = {{ standby_logdir }}/relay-log.info
|
||||
master-info-repository = TABLE
|
||||
relay-log-info-repository = TABLE
|
13
tests/integration/targets/setup_mysql/defaults/main.yml
Normal file
13
tests/integration/targets/setup_mysql/defaults/main.yml
Normal file
|
@ -0,0 +1,13 @@
|
|||
dbdeployer_version: 1.52.0
|
||||
dbdeployer_home_dir: /opt/dbdeployer
|
||||
|
||||
home_dir: /root
|
||||
|
||||
percona_client_version: 5.7
|
||||
|
||||
mariadb_install: false
|
||||
|
||||
mysql_version: 8.0.20
|
||||
mariadb_version: 10.5.4
|
||||
|
||||
mysql_base_port: 3306
|
6
tests/integration/targets/setup_mysql/handlers/main.yml
Normal file
6
tests/integration/targets/setup_mysql/handlers/main.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
- name: "{{ role_name }} | handler | create dbdeployer installed file"
|
||||
template:
|
||||
src: installed_file.j2
|
||||
dest: "{{ dbdeployer_installed_file }}"
|
||||
listen: create zookeeper installed file
|
15
tests/integration/targets/setup_mysql/tasks/config.yml
Normal file
15
tests/integration/targets/setup_mysql/tasks/config.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
- name: "{{ role_name }} | config | download mysql tarball"
|
||||
get_url:
|
||||
url: "{{ install_src }}"
|
||||
dest: "{{ dbdeployer_sandbox_download_dir }}/{{ install_tarball }}"
|
||||
|
||||
- name: "{{ role_name }} | config | run unpack tarball"
|
||||
shell:
|
||||
cmd: "dbdeployer unpack {{ dbdeployer_sandbox_download_dir }}/{{ install_tarball }}"
|
||||
creates: "{{ dbdeployer_sandbox_binary_dir }}/{{ install_version }}"
|
||||
|
||||
- name: "{{ role_name }} | config | setup replication topology"
|
||||
shell:
|
||||
cmd: "dbdeployer deploy multiple {{ install_version }} --base-port {{ mysql_base_port }}"
|
||||
creates: "{{ dbdeployer_sandbox_home_dir }}/rsandbox_{{ install_version|replace('.','_') }}"
|
11
tests/integration/targets/setup_mysql/tasks/dir.yml
Normal file
11
tests/integration/targets/setup_mysql/tasks/dir.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
- name: "{{ role_name }} | dir | create dbdeployer directories"
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ item }}"
|
||||
loop:
|
||||
- "{{ dbdeployer_home_dir }}"
|
||||
- "{{ dbdeployer_install_dir }}"
|
||||
- "{{ dbdeployer_sandbox_download_dir }}"
|
||||
- "{{ dbdeployer_sandbox_binary_dir }}"
|
||||
- "{{ dbdeployer_sandbox_home_dir }}"
|
52
tests/integration/targets/setup_mysql/tasks/install.yml
Normal file
52
tests/integration/targets/setup_mysql/tasks/install.yml
Normal file
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
- name: "{{ role_name }} | install | add apt signing key for percona"
|
||||
apt_key:
|
||||
keyserver: keyserver.ubuntu.com
|
||||
id: 4D1BB29D63D98E422B2113B19334A25F8507EFA5
|
||||
state: present
|
||||
|
||||
- name: "{{ role_name }} | install | add percona repositories"
|
||||
apt_repository:
|
||||
repo: "{{ item }}"
|
||||
state: present
|
||||
loop: "{{ percona_mysql_repos }}"
|
||||
|
||||
- name: "{{ role_name }} | install | install packages required by percona"
|
||||
apt:
|
||||
name: "{{ percona_mysql_packages }}"
|
||||
state: present
|
||||
environment:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
|
||||
- name: "{{ role_name }} | install | install python packages"
|
||||
pip:
|
||||
name: "{{ python_packages }}"
|
||||
|
||||
- name: "{{ role_name }} | install | install packages required by mysql"
|
||||
apt:
|
||||
name: "{{ install_prereqs }}"
|
||||
state: present
|
||||
environment:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
|
||||
- name: "{{ role_name }} | install | download and unpack dbdeployer"
|
||||
unarchive:
|
||||
remote_src: true
|
||||
src: "{{ dbdeployer_src }}"
|
||||
dest: "{{ dbdeployer_install_dir }}"
|
||||
creates: "{{ dbdeployer_installed_file }}"
|
||||
register: dbdeployer_tarball_install
|
||||
notify:
|
||||
- create zookeeper installed file
|
||||
until: dbdeployer_tarball_install is not failed
|
||||
retries: 6
|
||||
delay: 5
|
||||
|
||||
- name: "{{ role_name }} | install | create symlink"
|
||||
file:
|
||||
src: "{{ dbdeployer_install_dir }}/dbdeployer-{{ dbdeployer_version }}.linux"
|
||||
dest: /usr/local/bin/dbdeployer
|
||||
follow: false
|
||||
state: link
|
||||
|
||||
- meta: flush_handlers
|
6
tests/integration/targets/setup_mysql/tasks/main.yml
Normal file
6
tests/integration/targets/setup_mysql/tasks/main.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
- import_tasks: setvars.yml
|
||||
- import_tasks: dir.yml
|
||||
- import_tasks: install.yml
|
||||
- import_tasks: config.yml
|
||||
- import_tasks: verify.yml
|
28
tests/integration/targets/setup_mysql/tasks/setvars.yml
Normal file
28
tests/integration/targets/setup_mysql/tasks/setvars.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
- name: "{{ role_name }} | setvars | split mysql version in parts"
|
||||
set_fact:
|
||||
mysql_version_parts: "{{ mysql_version.split('.') }}"
|
||||
|
||||
- name: "{{ role_name }} | setvars | get mysql major version"
|
||||
set_fact:
|
||||
mysql_major_version: "{{ mysql_version_parts[0] + '.' + mysql_version_parts[1] }}"
|
||||
|
||||
- name: "{{ role_name }} | setvars | set the appropriate extension dependent on the mysql version"
|
||||
set_fact:
|
||||
mysql_compression_extension: "{{ mysql_version is version('8.0.0', '<') | ternary('gz', 'xz') }}"
|
||||
|
||||
- name: "{{ role_name }} | setvars | set the install type"
|
||||
set_fact:
|
||||
install_type: "{{ mariadb_install | ternary('mariadb', 'mysql') }}"
|
||||
|
||||
- name: "{{ role_name }} | setvars | set install_version"
|
||||
set_fact:
|
||||
install_version: "{{ lookup('vars', install_type + '_version') }}"
|
||||
|
||||
- name: "{{ role_name }} | setvars | set install_tarball"
|
||||
set_fact:
|
||||
install_tarball: "{{ lookup('vars', install_type + '_tarball') }}"
|
||||
|
||||
- name: "{{ role_name }} | setvars | set install_src"
|
||||
set_fact:
|
||||
install_src: "{{ lookup('vars', install_type + '_src') }}"
|
27
tests/integration/targets/setup_mysql/tasks/verify.yml
Normal file
27
tests/integration/targets/setup_mysql/tasks/verify.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
- name: "{{ role_name }} | verify | confirm primary is running and get the port"
|
||||
shell: "{{ dbdeployer_sandbox_home_dir }}/rsandbox_{{ install_version|replace('.','_') }}/m -BNe'select @@port'"
|
||||
register: primary_port
|
||||
|
||||
- name: "{{ role_name }} | verify | confirm replica1 is running and get the port"
|
||||
shell: "{{ dbdeployer_sandbox_home_dir }}/rsandbox_{{ install_version|replace('.','_') }}/s1 -BNe'select @@port'"
|
||||
register: replica1_port
|
||||
|
||||
- name: "{{ role_name }} | verify | confirm replica2 is running and get the port"
|
||||
shell: "{{ dbdeployer_sandbox_home_dir }}/rsandbox_{{ install_version|replace('.','_') }}/s2 -BNe'select @@port'"
|
||||
register: replica2_port
|
||||
|
||||
- name: "{{ role_name }} | verify | confirm primary is running on expected port"
|
||||
assert:
|
||||
that:
|
||||
- primary_port.stdout|int == 3307
|
||||
|
||||
- name: "{{ role_name }} | verify | confirm replica1 is running on expected port"
|
||||
assert:
|
||||
that:
|
||||
- replica1_port.stdout|int == 3308
|
||||
|
||||
- name: "{{ role_name }} | verify | confirm replica2 is running on expected port"
|
||||
assert:
|
||||
that:
|
||||
- replica2_port.stdout|int == 3309
|
|
@ -0,0 +1 @@
|
|||
{{ dbdeployer_version }}
|
27
tests/integration/targets/setup_mysql/vars/main.yml
Normal file
27
tests/integration/targets/setup_mysql/vars/main.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
dbdeployer_install_dir: "{{ dbdeployer_home_dir }}/dbdeployer_{{ dbdeployer_version }}"
|
||||
dbdeployer_src: "https://github.com/datacharmer/dbdeployer/releases/download/v{{ dbdeployer_version }}/dbdeployer-{{ dbdeployer_version }}.linux.tar.gz"
|
||||
dbdeployer_installed_file: "{{ dbdeployer_home_dir }}/dbdeployer_installed"
|
||||
|
||||
dbdeployer_sandbox_download_dir: "{{ home_dir }}/downloads"
|
||||
dbdeployer_sandbox_binary_dir: "{{ home_dir }}/opt/mysql"
|
||||
dbdeployer_sandbox_home_dir: "{{ home_dir }}/sandboxes"
|
||||
|
||||
percona_mysql_repos:
|
||||
- deb http://repo.percona.com/apt {{ ansible_lsb.codename }} main
|
||||
- deb-src http://repo.percona.com/apt {{ ansible_lsb.codename }} main
|
||||
|
||||
percona_mysql_packages:
|
||||
- percona-server-client-{{ percona_client_version }}
|
||||
|
||||
python_packages:
|
||||
- pymysql
|
||||
|
||||
install_prereqs:
|
||||
- libaio1
|
||||
- libnuma1
|
||||
|
||||
mysql_tarball: "mysql-{{ mysql_version }}-linux-glibc2.12-x86_64.tar.{{ mysql_compression_extension }}"
|
||||
mysql_src: "https://dev.mysql.com/get/Downloads/MySQL-{{ mysql_major_version }}/{{ mysql_tarball }}"
|
||||
mariadb_tarball: "mariadb-{{ mariadb_version }}-linux-x86_64.tar.gz"
|
||||
mariadb_src: "https://downloads.mariadb.com/MariaDB/mariadb-{{ mariadb_version }}/bintar-linux-x86_64/{{ mariadb_tarball }}"
|
|
@ -0,0 +1,5 @@
|
|||
- name: delete temporary directory
|
||||
include_tasks: default-cleanup.yml
|
||||
|
||||
- name: delete temporary directory (windows)
|
||||
include_tasks: windows-cleanup.yml
|
|
@ -0,0 +1,5 @@
|
|||
- name: delete temporary directory
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}"
|
||||
state: absent
|
||||
no_log: yes
|
|
@ -0,0 +1,11 @@
|
|||
- name: create temporary directory
|
||||
tempfile:
|
||||
state: directory
|
||||
suffix: .test
|
||||
register: remote_tmp_dir
|
||||
notify:
|
||||
- delete temporary directory
|
||||
|
||||
- name: record temporary directory
|
||||
set_fact:
|
||||
remote_tmp_dir: "{{ remote_tmp_dir.path }}"
|
|
@ -0,0 +1,10 @@
|
|||
- name: make sure we have the ansible_os_family and ansible_distribution_version facts
|
||||
setup:
|
||||
gather_subset: distribution
|
||||
when: ansible_facts == {}
|
||||
|
||||
- include_tasks: "{{ lookup('first_found', files)}}"
|
||||
vars:
|
||||
files:
|
||||
- "{{ ansible_os_family | lower }}.yml"
|
||||
- "default.yml"
|
|
@ -1,5 +1,9 @@
|
|||
---
|
||||
# defaults file for test_mysql_db
|
||||
mysql_user: root
|
||||
mysql_password: msandbox
|
||||
mysql_primary_port: 3307
|
||||
|
||||
db_name: 'data'
|
||||
db_name2: 'data2'
|
||||
db_user1: 'datauser1'
|
2
tests/integration/targets/test_mysql_db/meta/main.yml
Normal file
2
tests/integration/targets/test_mysql_db/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- setup_mysql
|
|
@ -1,8 +1,8 @@
|
|||
- set_fact:
|
||||
db_to_create=testdb1
|
||||
config_file="/root/.my1.cnf"
|
||||
fake_port=9999
|
||||
fake_host="blahblah.local"
|
||||
db_to_create: testdb1
|
||||
config_file: "/root/.my1.cnf"
|
||||
fake_port: 9999
|
||||
fake_host: "blahblah.local"
|
||||
|
||||
- name: Create custom config file
|
||||
shell: 'echo "[client]" > {{ config_file }}'
|
||||
|
@ -12,6 +12,10 @@
|
|||
|
||||
- name: Create database using fake port to connect to, must fail
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_to_create }}'
|
||||
state: present
|
||||
check_implicit_admin: yes
|
||||
|
@ -28,12 +32,15 @@
|
|||
|
||||
- name: Create database using default port
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_to_create }}'
|
||||
state: present
|
||||
check_implicit_admin: yes
|
||||
config_file: '{{ config_file }}'
|
||||
config_overrides_defaults: no
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: Must not fail because of the default of login_port is correct
|
||||
|
@ -49,6 +56,10 @@
|
|||
|
||||
- name: Remove database using fake login_host
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_to_create }}'
|
||||
state: absent
|
||||
config_file: '{{ config_file }}'
|
||||
|
@ -65,7 +76,10 @@
|
|||
# Clean up
|
||||
- name: Remove test db
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_to_create }}'
|
||||
state: absent
|
||||
check_implicit_admin: yes
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
|
@ -1,78 +1,98 @@
|
|||
---
|
||||
|
||||
- set_fact:
|
||||
latin1_file1="{{tmp_dir}}/{{file}}"
|
||||
- set_fact:
|
||||
latin1_file1: "{{tmp_dir}}/{{file}}"
|
||||
|
||||
- name: Deleting Latin1 encoded Database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_latin1_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: create Latin1 encoded database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_latin1_name }}'
|
||||
state: present
|
||||
encoding: latin1
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: create a table in Latin1 database
|
||||
command: mysql {{ db_latin1_name }} -e 'create table testlatin1(id int, name varchar(100));'
|
||||
command: "{{ mysql_command }} {{ db_latin1_name }} -e \"create table testlatin1(id int, name varchar(100))\""
|
||||
|
||||
|
||||
# Inserting a string in latin1 into table, , this string be tested later,
|
||||
# Inserting a string in latin1 into table, , this string be tested later,
|
||||
# so report any change of content in the test too
|
||||
- name: inserting data into Latin1 database
|
||||
command: mysql {{ db_latin1_name }} -e "insert into testlatin1 value(47,'Amédée Bôlüt');"
|
||||
command: "{{ mysql_command }} {{ db_latin1_name }} -e \"insert into testlatin1 value(47,'Amédée Bôlüt')\""
|
||||
|
||||
- name: selecting table
|
||||
command: mysql {{ db_latin1_name }} -e "select * from testlatin1;"
|
||||
command: "{{ mysql_command }} {{ db_latin1_name }} -e \"select * from testlatin1\""
|
||||
register: output
|
||||
|
||||
- name: Dumping a table in Latin1 database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: "{{ db_latin1_name }}"
|
||||
encoding: latin1
|
||||
target: "{{ latin1_file1 }}"
|
||||
state: dump
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: dump_result
|
||||
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: state dump - file name should exist
|
||||
file: name={{ latin1_file1 }} state=file
|
||||
file:
|
||||
name: '{{ latin1_file1 }}'
|
||||
state: file
|
||||
|
||||
- name: od the file and check of latin1 encoded string is present
|
||||
shell: grep -a 47 {{ latin1_file1 }} | od -c |grep "A m 351 d 351 e B 364\|A m 303 251 d 303 251 e B 303"
|
||||
|
||||
- name: Dropping {{ db_latin1_name }} database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_latin1_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: Importing the latin1 mysql script
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
state: import
|
||||
encoding: latin1
|
||||
name: '{{ db_latin1_name }}'
|
||||
target: "{{ latin1_file1 }}"
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
|
||||
- name: check encoding of table
|
||||
shell: mysql {{ db_latin1_name }} -e "SHOW FULL COLUMNS FROM testlatin1;"
|
||||
shell: "{{ mysql_command }} {{ db_latin1_name }} -e \"SHOW FULL COLUMNS FROM testlatin1\""
|
||||
register: output
|
||||
failed_when: '"latin1_swedish_ci" not in output.stdout'
|
||||
|
||||
- name: remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_latin1_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
|
@ -17,236 +17,292 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ============================================================
|
||||
- name: alias mysql command to include default options
|
||||
set_fact:
|
||||
mysql_command: "mysql -u{{ mysql_user }} -p{{ mysql_password }} -P{{ mysql_primary_port }} --protocol=tcp"
|
||||
|
||||
- name: remove database if it exists
|
||||
command: >
|
||||
mysql -sse "drop database {{db_name}};"
|
||||
"{{ mysql_command }} -sse 'drop database {{ db_name }}'"
|
||||
ignore_errors: True
|
||||
|
||||
- name: make sure the test database is not there
|
||||
command: mysql {{db_name}}
|
||||
command: "{{ mysql_command }} {{ db_name }}"
|
||||
register: mysql_db_check
|
||||
failed_when: "'1049' not in mysql_db_check.stderr"
|
||||
|
||||
- name: test state=present for a database name (expect changed=true)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message that database exist
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.db == '{{ db_name }}'
|
||||
- result.executed_commands == ["CREATE DATABASE `{{ db_name }}`"]
|
||||
- result is changed
|
||||
- result.db == '{{ db_name }}'
|
||||
- result.executed_commands == ["CREATE DATABASE `{{ db_name }}`"]
|
||||
|
||||
- name: run command to test state=present for a database name (expect db_name in stdout)
|
||||
command: mysql "-e show databases like '{{ db_name }}';"
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_name }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database exist
|
||||
assert: { that: "'{{ db_name }}' in result.stdout" }
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_name }}' in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: test state=absent for a database name (expect changed=true)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message that database does not exist
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.db == '{{ db_name }}'
|
||||
- result.executed_commands == ["DROP DATABASE `{{ db_name }}`"]
|
||||
- result is changed
|
||||
- result.db == '{{ db_name }}'
|
||||
- result.executed_commands == ["DROP DATABASE `{{ db_name }}`"]
|
||||
|
||||
- name: run command to test state=absent for a database name (expect db_name not in stdout)
|
||||
command: mysql "-e show databases like '{{ db_name }}';"
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_name }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database does not exist
|
||||
assert: { that: "'{{ db_name }}' not in result.stdout" }
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_name }}' not in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: test mysql_db encoding param not valid - issue 8075
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: datanotvalid
|
||||
state: present
|
||||
encoding: notvalid
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- name: assert test mysql_db encoding param not valid - issue 8075 (failed=true)
|
||||
assert:
|
||||
that:
|
||||
- "result.failed == true"
|
||||
- "'Traceback' not in result.msg"
|
||||
- "'Unknown character set' in result.msg"
|
||||
- "result.failed == true"
|
||||
- "'Traceback' not in result.msg"
|
||||
- "'Unknown character set' in result.msg"
|
||||
|
||||
# ============================================================
|
||||
- name: test mysql_db using a valid encoding utf8 (expect changed=true)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: 'en{{ db_name }}'
|
||||
state: present
|
||||
encoding: utf8
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message created a database
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'utf8'"]
|
||||
- result is changed
|
||||
- result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'utf8'"]
|
||||
|
||||
- name: test database was created
|
||||
command: mysql "-e SHOW CREATE DATABASE en{{ db_name }};"
|
||||
command: "{{ mysql_command }} -e \"SHOW CREATE DATABASE en{{ db_name }}\""
|
||||
register: result
|
||||
|
||||
- name: assert created database is of encoding utf8
|
||||
assert: { that: "'utf8' in result.stdout" }
|
||||
assert:
|
||||
that:
|
||||
- "'utf8' in result.stdout"
|
||||
|
||||
- name: remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: 'en{{ db_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
# ============================================================
|
||||
- name: test mysql_db using valid encoding binary (expect changed=true)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: 'en{{ db_name }}'
|
||||
state: present
|
||||
encoding: binary
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message that database was created
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'binary'"]
|
||||
- result is changed
|
||||
- result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'binary'"]
|
||||
|
||||
- name: run command to test database was created
|
||||
command: mysql "-e SHOW CREATE DATABASE en{{ db_name }};"
|
||||
command: "{{ mysql_command }} -e \"SHOW CREATE DATABASE en{{ db_name }}\""
|
||||
register: result
|
||||
|
||||
- name: assert created database is of encoding binary
|
||||
assert: { that: "'binary' in result.stdout" }
|
||||
assert:
|
||||
that:
|
||||
- "'binary' in result.stdout"
|
||||
|
||||
- name: remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: 'en{{ db_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
# ============================================================
|
||||
- name: create user1 to access database dbuser1
|
||||
mysql_user:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: user1
|
||||
password: 'Hfd6fds^dfA8Ga'
|
||||
priv: '*.*:ALL'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: create database dbuser1 using user1
|
||||
mysql_db:
|
||||
name: '{{ db_user1 }}'
|
||||
state: present
|
||||
login_user: user1
|
||||
login_password: 'Hfd6fds^dfA8Ga'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_user1 }}'
|
||||
state: present
|
||||
register: result
|
||||
|
||||
- name: assert output message that database was created
|
||||
assert: { that: "result.changed == true" }
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: run command to test database was created using user1
|
||||
command: mysql "-e show databases like '{{ db_user1 }}';"
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_user1 }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database exist
|
||||
assert: { that: "'{{ db_user1 }}' in result.stdout" }
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_user1 }}' in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: create user2 to access database with privilege select only
|
||||
mysql_user:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: user2
|
||||
password: 'kjsfd&F7safjad'
|
||||
priv: '*.*:SELECT'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: create database dbuser2 using user2 with no privilege to create (expect failed=true)
|
||||
mysql_db:
|
||||
name: '{{ db_user2 }}'
|
||||
state: present
|
||||
login_user: user2
|
||||
login_password: 'kjsfd&F7safjad'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_user2 }}'
|
||||
state: present
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- name: assert output message that database was not created using dbuser2
|
||||
assert:
|
||||
that:
|
||||
- "result.failed == true"
|
||||
- "'Access denied' in result.msg"
|
||||
- "result.failed == true"
|
||||
- "'Access denied' in result.msg"
|
||||
|
||||
- name: run command to test that database was not created
|
||||
command: mysql "-e show databases like '{{ db_user2 }}';"
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_user2 }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database does not exist
|
||||
assert: { that: "'{{ db_user2 }}' not in result.stdout" }
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_user2 }}' not in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: delete database using user2 with no privilege to delete (expect failed=true)
|
||||
mysql_db:
|
||||
name: '{{ db_user1 }}'
|
||||
state: absent
|
||||
login_user: user2
|
||||
login_password: 'kjsfd&F7safjad'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_user1 }}'
|
||||
state: absent
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- name: assert output message that database was not deleted using dbuser2
|
||||
assert:
|
||||
that:
|
||||
- "result.failed == true"
|
||||
- "'Access denied' in result.msg"
|
||||
- "result.failed == true"
|
||||
- "'Access denied' in result.msg"
|
||||
|
||||
- name: run command to test database was not deleted
|
||||
command: mysql "-e show databases like '{{ db_user1 }}';"
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_user1 }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database still exist
|
||||
assert: { that: "'{{ db_user1 }}' in result.stdout" }
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_user1 }}' in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: delete database using user1 with all privilege to delete a database (expect changed=true)
|
||||
mysql_db:
|
||||
name: '{{ db_user1 }}'
|
||||
state: absent
|
||||
login_user: user1
|
||||
login_password: 'Hfd6fds^dfA8Ga'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_user1 }}'
|
||||
state: absent
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- name: assert output message that database was deleted using user1
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_commands == ["DROP DATABASE `{{ db_user1 }}`"]
|
||||
- result is changed
|
||||
- result.executed_commands == ["DROP DATABASE `{{ db_user1 }}`"]
|
||||
|
||||
- name: run command to test database was deleted using user1
|
||||
command: mysql "-e show databases like '{{ db_name }}';"
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_name }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database does not exist
|
||||
assert: { that: "'{{ db_user1 }}' not in result.stdout" }
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_user1 }}' not in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- include: state_dump_import.yml format_type=sql file=dbdata.sql format_msg_type=ASCII file2=dump2.sql file3=dump3.sql file4=dump4.sql
|
||||
|
@ -255,7 +311,7 @@
|
|||
|
||||
- include: state_dump_import.yml format_type=bz2 file=dbdata.bz2 format_msg_type=bzip2 file2=dump2.bz2 file3=dump3.bz2 file4=dump4.bz2
|
||||
|
||||
- include: multi_db_create_delete.yml
|
||||
- include: multi_db_create_delete.yml
|
||||
|
||||
- include: encoding_dump_import.yml file=latin1.sql format_msg_type=ASCII
|
||||
|
|
@ -2,20 +2,20 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
- set_fact:
|
||||
db1_name="database1"
|
||||
db2_name="database2"
|
||||
db3_name="database3"
|
||||
db4_name="database4"
|
||||
db5_name="database5"
|
||||
dump1_file="/tmp/dump1_file.sql"
|
||||
dump2_file="/tmp/all.sql"
|
||||
db1_name: "database1"
|
||||
db2_name: "database2"
|
||||
db3_name: "database3"
|
||||
db4_name: "database4"
|
||||
db5_name: "database5"
|
||||
dump1_file: "/tmp/dump1_file.sql"
|
||||
dump2_file: "/tmp/all.sql"
|
||||
|
||||
# ============================== CREATE TEST ===============================
|
||||
#
|
||||
# ==========================================================================
|
||||
# Initial check - To confirm that database does not exist before executing check mode tasks
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases does not exist
|
||||
|
@ -29,22 +29,25 @@
|
|||
# Create multiple databases that does not exists (check mode)
|
||||
- name: Create multiple databases that does not exists (check mode)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: check_mode_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert successful completion of create database using check_mode since databases does not exist prior
|
||||
assert:
|
||||
that:
|
||||
- check_mode_result.changed == true
|
||||
- check_mode_result.changed == true
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases does not exist (since created via check mode)
|
||||
|
@ -58,22 +61,25 @@
|
|||
# Create multiple databases
|
||||
- name: Create multiple databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert successful completion of create database
|
||||
assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.db_list == ['{{ db1_name }}', '{{ db2_name }}', '{{ db3_name }}']
|
||||
- result.changed == true
|
||||
- result.db_list == ['{{ db1_name }}', '{{ db2_name }}', '{{ db3_name }}']
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases exist after creation
|
||||
|
@ -87,22 +93,25 @@
|
|||
# Recreate already existing databases (check mode)
|
||||
- name: Recreate already existing databases (check mode)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: check_mode_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert that recreation of existing databases does not make change (since recreated using check mode)
|
||||
assert:
|
||||
that:
|
||||
- check_mode_result.changed == false
|
||||
- check_mode_result.changed == false
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases exist (since performed recreation of existing databases via check mode)
|
||||
|
@ -116,21 +125,24 @@
|
|||
# Recreate same databases
|
||||
- name: Recreate multiple databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert that recreation of existing databases does not make change
|
||||
assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.changed == false
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases does priorly exist
|
||||
|
@ -144,19 +156,22 @@
|
|||
# Delete one of the databases (db2 here)
|
||||
- name: Delete db2 database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert successful completion of deleting database
|
||||
assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.changed == true
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that only db2 database does not exist
|
||||
|
@ -170,22 +185,25 @@
|
|||
# Recreate multiple databases in which few databases does not exists (check mode)
|
||||
- name: Recreate multiple databases in which few databases does not exists (check mode)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: check_mode_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert successful completion of recreation of partially existing database using check mode
|
||||
assert:
|
||||
that:
|
||||
- check_mode_result.changed == true
|
||||
- check_mode_result.changed == true
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that recreated non existing databases does not exist (since created via check mode)
|
||||
|
@ -194,26 +212,29 @@
|
|||
- "'{{ db1_name }}' in mysql_result.stdout"
|
||||
- "'{{ db2_name }}' not in mysql_result.stdout"
|
||||
- "'{{ db3_name }}' in mysql_result.stdout"
|
||||
|
||||
|
||||
# ==========================================================================
|
||||
# Create multiple databases
|
||||
- name: Create multiple databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert successful completion of create database
|
||||
assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.changed == true
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases exist
|
||||
|
@ -228,28 +249,33 @@
|
|||
# ==========================================================================
|
||||
# Check that dump file does not exist
|
||||
- name: Dump file does not exist
|
||||
file: name={{ dump1_file }} state=absent
|
||||
file:
|
||||
name: '{{ dump1_file }}'
|
||||
state: absent
|
||||
|
||||
# ==========================================================================
|
||||
# Dump existing databases (check mode)
|
||||
- name: Dump existing databases (check mode)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: dump
|
||||
target: '{{ dump1_file }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: check_mode_dump_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert successful completion of dump operation using check mode
|
||||
assert:
|
||||
that:
|
||||
- check_mode_dump_result.changed == true
|
||||
- check_mode_dump_result.changed == true
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases exist (check mode)
|
||||
|
@ -260,18 +286,23 @@
|
|||
- "'{{ db3_name }}' in mysql_result.stdout"
|
||||
|
||||
- name: state dump - file name should not exist (since dumped via check mode)
|
||||
file: name={{ dump1_file }} state=absent
|
||||
file:
|
||||
name: '{{ dump1_file }}'
|
||||
state: absent
|
||||
|
||||
# ==========================================================================
|
||||
# Dump existing and non-existing databases (check mode)
|
||||
- name: Dump existing and non-existing databases (check mode)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- "{{ db1_name }}"
|
||||
- "{{ db4_name }}"
|
||||
- "{{ db3_name }}"
|
||||
state: dump
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
target: "{{ dump1_file }}"
|
||||
register: check_mode_dump_result
|
||||
ignore_errors: True
|
||||
|
@ -280,10 +311,10 @@
|
|||
- name: assert that dump operation of existing and non existing databases does not make change (using check mode)
|
||||
assert:
|
||||
that:
|
||||
- "'Cannot dump database' in check_mode_dump_result['msg']"
|
||||
- "'Cannot dump database' in check_mode_dump_result['msg']"
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases exist (since check mode)
|
||||
|
@ -295,18 +326,23 @@
|
|||
- "'{{ db4_name }}' not in mysql_result.stdout"
|
||||
|
||||
- name: state dump - file name should not exist (since prior dump operation performed via check mode)
|
||||
file: name={{ dump1_file }} state=absent
|
||||
file:
|
||||
name: '{{ dump1_file }}'
|
||||
state: absent
|
||||
|
||||
# ==========================================================================
|
||||
# Dump non-existing databases (check mode)
|
||||
- name: Dump non-existing databases (check mode)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- "{{ db4_name }}"
|
||||
- "{{ db5_name }}"
|
||||
state: dump
|
||||
target: "{{ dump1_file }}"
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: check_mode_dump_result
|
||||
ignore_errors: True
|
||||
check_mode: yes
|
||||
|
@ -314,10 +350,10 @@
|
|||
- name: assert successful completion of dump operation using check mode
|
||||
assert:
|
||||
that:
|
||||
- "'Cannot dump database' in check_mode_dump_result['msg']"
|
||||
- "'Cannot dump database' in check_mode_dump_result['msg']"
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases exist (since delete via check mode)
|
||||
|
@ -330,29 +366,34 @@
|
|||
- "'{{ db5_name }}' not in mysql_result.stdout"
|
||||
|
||||
- name: state dump - file name should not exist (since prior dump operation performed via check mode)
|
||||
file: name={{ dump1_file }} state=absent
|
||||
file:
|
||||
name: '{{ dump1_file }}'
|
||||
state: absent
|
||||
|
||||
# ==========================================================================
|
||||
# Dump existing databases
|
||||
- name: Dump existing databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: dump
|
||||
target: '{{ dump1_file }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: dump_result
|
||||
|
||||
- name: assert successful completion of dump operation
|
||||
assert:
|
||||
that:
|
||||
- dump_result.changed == true
|
||||
- dump_result.db_list == ['{{ db1_name }}', '{{ db2_name }}', '{{ db3_name }}']
|
||||
- dump_result.changed == true
|
||||
- dump_result.db_list == ['{{ db1_name }}', '{{ db2_name }}', '{{ db3_name }}']
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases exist
|
||||
|
@ -363,7 +404,9 @@
|
|||
- "'{{ db3_name }}' in mysql_result.stdout"
|
||||
|
||||
- name: state dump - file name should exist
|
||||
file: name={{ dump1_file }} state=file
|
||||
file:
|
||||
name: '{{ dump1_file }}'
|
||||
state: file
|
||||
|
||||
- name: Check if db1 database create command is present in the dumped file
|
||||
shell: "grep -i 'CREATE DATABASE.*`{{ db1_name }}`' {{ dump1_file }}"
|
||||
|
@ -378,23 +421,28 @@
|
|||
# Dump all databases
|
||||
|
||||
- name: state dump - dump2 file name should not exist
|
||||
file: name={{ dump2_file }} state=absent
|
||||
file:
|
||||
name: '{{ dump2_file }}'
|
||||
state: absent
|
||||
|
||||
- name: Dump existing databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: all
|
||||
state: dump
|
||||
target: '{{ dump2_file }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: dump_result
|
||||
|
||||
- name: assert successful completion of dump operation
|
||||
assert:
|
||||
that:
|
||||
- dump_result.changed == true
|
||||
- dump_result.changed == true
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases exist
|
||||
|
@ -407,7 +455,9 @@
|
|||
- "'{{ db5_name }}' not in mysql_result.stdout"
|
||||
|
||||
- name: state dump - file name should exist
|
||||
file: name={{ dump2_file }} state=file
|
||||
file:
|
||||
name: '{{ dump2_file }}'
|
||||
state: file
|
||||
|
||||
# ============================ DELETE TEST =================================
|
||||
#
|
||||
|
@ -415,21 +465,24 @@
|
|||
# Delete multiple databases which already exists (check mode)
|
||||
- name: Delete multiple databases which already exists (check mode)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: check_mode_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert successful completion of delete databases which already exists using check mode
|
||||
assert:
|
||||
that:
|
||||
- check_mode_result.changed == true
|
||||
- check_mode_result.changed == true
|
||||
|
||||
- name: run command to test state=absent for a database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases exist even after deleting (since deleted via check mode)
|
||||
|
@ -442,21 +495,24 @@
|
|||
# Delete multiple databases
|
||||
- name: Delete multiple databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db3_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert successful completion of deleting database
|
||||
assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.db_list == ['{{ db2_name }}', '{{ db3_name }}']
|
||||
- result.changed == true
|
||||
- result.db_list == ['{{ db2_name }}', '{{ db3_name }}']
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases does not exist
|
||||
|
@ -469,21 +525,24 @@
|
|||
# Delete non existing databases (check mode)
|
||||
- name: Delete non existing databases (check mode)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db4_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: check_mode_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert that deletion of non existing databases does not make change (using check mode)
|
||||
assert:
|
||||
that:
|
||||
- check_mode_result.changed == false
|
||||
- check_mode_result.changed == false
|
||||
|
||||
- name: run command to test state=absent for a database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases does not exist since were deleted priorly (check mode)
|
||||
|
@ -496,20 +555,23 @@
|
|||
# Delete already deleted databases
|
||||
- name: Delete already deleted databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
- '{{ db4_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert that deletion of non existing databases does not make change
|
||||
assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.changed == false
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that databases does not exists
|
||||
|
@ -522,6 +584,10 @@
|
|||
# Delete all databases
|
||||
- name: Delete all databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
- '{{ db2_name }}'
|
||||
|
@ -529,16 +595,15 @@
|
|||
- '{{ db4_name }}'
|
||||
- '{{ db5_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert successful completion of deleting database
|
||||
assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.changed == true
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
command: mysql "-e show databases like 'database%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that specific databases does not exist
|
||||
|
@ -551,7 +616,11 @@
|
|||
- "'{{ db5_name }}' not in mysql_result.stdout"
|
||||
|
||||
- name: state dump - dump 1 file name should be removed
|
||||
file: name={{ dump1_file }} state=absent
|
||||
file:
|
||||
name: '{{ dump1_file }}'
|
||||
state: absent
|
||||
|
||||
- name: state dump - dump 2 file name should be removed
|
||||
file: name={{ dump2_file }} state=absent
|
||||
file:
|
||||
name: '{{ dump2_file }}'
|
||||
state: absent
|
|
@ -18,71 +18,87 @@
|
|||
|
||||
# ============================================================
|
||||
- set_fact:
|
||||
db_file_name="{{tmp_dir}}/{{file}}"
|
||||
wrong_sql_file="{{tmp_dir}}/wrong.sql"
|
||||
dump_file1="{{tmp_dir}}/{{file2}}"
|
||||
dump_file2="{{tmp_dir}}/{{file3}}"
|
||||
db_user="test"
|
||||
db_user_unsafe_password="pass!word"
|
||||
config_file="/root/.my.cnf"
|
||||
db_file_name: "{{ tmp_dir }}/{{ file }}"
|
||||
wrong_sql_file: "{{ tmp_dir }}/wrong.sql"
|
||||
dump_file1: "{{ tmp_dir }}/{{ file2 }}"
|
||||
dump_file2: "{{ tmp_dir }}/{{ file3 }}"
|
||||
db_user: "test"
|
||||
db_user_unsafe_password: "pass!word"
|
||||
config_file: "/root/.my.cnf"
|
||||
|
||||
- name: create custom config file
|
||||
shell: 'echo "[client]" > {{ config_file }}'
|
||||
|
||||
- name: create user for test unsafe_login_password parameter
|
||||
mysql_user:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_user }}'
|
||||
password: '{{ db_user_unsafe_password }}'
|
||||
priv: '*.*:ALL'
|
||||
state: present
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: state dump/import - create database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: present
|
||||
check_implicit_admin: yes
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: create database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: present
|
||||
check_implicit_admin: no
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: state dump/import - create table department
|
||||
command: mysql {{ db_name }} '-e create table department(id int, name varchar(100));'
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e create table department(id int, name varchar(100))\""
|
||||
|
||||
- name: state dump/import - create table employee
|
||||
command: mysql {{ db_name }} '-e create table employee(id int, name varchar(100));'
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e create table employee(id int, name varchar(100))\""
|
||||
|
||||
- name: state dump/import - insert data into table employee
|
||||
command: mysql {{ db_name }} "-e insert into employee value(47,'Joe Smith');"
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e insert into employee value(47,'Joe Smith')\""
|
||||
|
||||
- name: state dump/import - insert data into table department
|
||||
command: mysql {{ db_name }} "-e insert into department value(2,'Engineering');"
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e insert into department value(2,'Engineering')\""
|
||||
|
||||
- name: state dump/import - file name should not exist
|
||||
file: name={{ db_file_name }} state=absent
|
||||
file:
|
||||
name: '{{ db_file_name }}'
|
||||
state: absent
|
||||
|
||||
- name: database dump file1 should not exist
|
||||
file: name={{ dump_file1 }} state=absent
|
||||
file:
|
||||
name: '{{ dump_file1 }}'
|
||||
state: absent
|
||||
|
||||
- name: database dump file2 should not exist
|
||||
file: name={{ dump_file2 }} state=absent
|
||||
file:
|
||||
name: '{{ dump_file2 }}'
|
||||
state: absent
|
||||
|
||||
- name: state dump without department table.
|
||||
mysql_db:
|
||||
login_user: '{{ db_user }}'
|
||||
login_password: '{{ db_user_unsafe_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
unsafe_login_password: yes
|
||||
name: "{{ db_name }}"
|
||||
name: '{{ db_name }}'
|
||||
state: dump
|
||||
target: "{{ db_file_name }}"
|
||||
target: '{{ db_file_name }}'
|
||||
ignore_tables:
|
||||
- "{{ db_name }}.department"
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
force: yes
|
||||
master_data: 1
|
||||
skip_lock_tables: yes
|
||||
|
@ -95,49 +111,59 @@
|
|||
- name: assert successful completion of dump operation
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_commands[0] is search("mysqldump --defaults-file={{ config_file }} --user={{ db_user }} --password=\*\*\*\*\*\*\*\* --force --socket={{ mysql_socket }} {{ db_name }} --skip-lock-tables --quick --ignore-table={{ db_name }}.department --master-data=1 --skip-triggers")
|
||||
- result is changed
|
||||
- result.executed_commands[0] is search("mysqldump --defaults-file={{ config_file }} --user={{ db_user }} --password=\*\*\*\*\*\*\*\* --force --host=127.0.0.1 --port={{ mysql_primary_port }} {{ db_name }} --skip-lock-tables --quick --ignore-table={{ db_name }}.department --master-data=1 --skip-triggers")
|
||||
|
||||
- name: state dump/import - file name should exist
|
||||
file: name={{ db_file_name }} state=file
|
||||
file:
|
||||
name: '{{ db_file_name }}'
|
||||
state: file
|
||||
|
||||
- name: state dump with multiple databases in comma separated form.
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: "{{ db_name }},{{ db_name2 }}"
|
||||
state: dump
|
||||
target: "{{ dump_file1 }}"
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
target: '{{ dump_file1 }}'
|
||||
check_implicit_admin: yes
|
||||
register: dump_result1
|
||||
|
||||
- name: assert successful completion of dump operation (with multiple databases in comma separated form)
|
||||
assert:
|
||||
that:
|
||||
- dump_result1 is changed
|
||||
- dump_result1.executed_commands[0] is search(" --user=root --password=''")
|
||||
- dump_result1 is changed
|
||||
- dump_result1.executed_commands[0] is search(" --user=root --password=\*\*\*\*\*\*\*\*")
|
||||
|
||||
- name: state dump - dump file1 should exist
|
||||
file: name={{ dump_file1 }} state=file
|
||||
file:
|
||||
name: '{{ dump_file1 }}'
|
||||
state: file
|
||||
|
||||
- name: state dump with multiple databases in list form via check_mode
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- "{{ db_name }}"
|
||||
- "{{ db_name2 }}"
|
||||
- '{{ db_name }}'
|
||||
- '{{ db_name2 }}'
|
||||
state: dump
|
||||
target: "{{ dump_file2 }}"
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
target: '{{ dump_file2 }}'
|
||||
register: dump_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert successful completion of dump operation (with multiple databases in list form) via check mode
|
||||
assert:
|
||||
that:
|
||||
- "dump_result.changed == true"
|
||||
- "dump_result.changed == true"
|
||||
|
||||
- name: database dump file2 should not exist
|
||||
stat:
|
||||
path: "{{ dump_file2 }}"
|
||||
path: '{{ dump_file2 }}'
|
||||
register: stat_result
|
||||
|
||||
- name: assert that check_mode does not create dump file for databases
|
||||
|
@ -147,75 +173,95 @@
|
|||
|
||||
- name: state dump with multiple databases in list form.
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- "{{ db_name }}"
|
||||
- "{{ db_name2 }}"
|
||||
- '{{ db_name }}'
|
||||
- '{{ db_name2 }}'
|
||||
state: dump
|
||||
target: "{{ dump_file2 }}"
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
target: '{{ dump_file2 }}'
|
||||
register: dump_result2
|
||||
|
||||
- name: assert successful completion of dump operation (with multiple databases in list form)
|
||||
assert:
|
||||
that:
|
||||
- "dump_result2.changed == true"
|
||||
- "dump_result2.changed == true"
|
||||
|
||||
- name: state dump - dump file2 should exist
|
||||
file: name={{ dump_file2 }} state=file
|
||||
file:
|
||||
name: '{{ dump_file2 }}'
|
||||
state: file
|
||||
|
||||
- name: state dump/import - remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: test state=import to restore the database of type {{ format_type }} (expect changed=true)
|
||||
mysql_db:
|
||||
login_user: '{{ db_user }}'
|
||||
login_password: '{{ db_user_unsafe_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
unsafe_login_password: yes
|
||||
name: '{{ db_name }}'
|
||||
state: import
|
||||
target: '{{ db_file_name }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
use_shell: yes
|
||||
register: result
|
||||
|
||||
- name: show the tables
|
||||
command: mysql {{ db_name }} "-e show tables;"
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e show tables\""
|
||||
register: result
|
||||
|
||||
- name: assert that the department table is absent.
|
||||
assert:
|
||||
that:
|
||||
- "'department' not in result.stdout"
|
||||
- "'department' not in result.stdout"
|
||||
|
||||
- name: test state=import to restore a database from multiple database dumped file1
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: import
|
||||
target: '{{ dump_file1 }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
use_shell: no
|
||||
register: import_result
|
||||
|
||||
- name: assert output message restored a database from dump file1
|
||||
assert: { that: "import_result.changed == true" }
|
||||
assert:
|
||||
that:
|
||||
- "import_result.changed == true"
|
||||
|
||||
- name: remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: run command to list databases
|
||||
command: mysql "-e show databases like 'data%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'data%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that db_name2 database does not exist
|
||||
|
@ -225,18 +271,23 @@
|
|||
|
||||
- name: test state=import to restore a database from dumped file2 (check mode)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: import
|
||||
target: '{{ dump_file2 }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: check_import_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert output message restored a database from dump file2 (check mode)
|
||||
assert: { that: "check_import_result.changed == true" }
|
||||
assert:
|
||||
that:
|
||||
- "check_import_result.changed == true"
|
||||
|
||||
- name: run command to list databases
|
||||
command: mysql "-e show databases like 'data%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'data%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that db_name2 database does not exist (check mode)
|
||||
|
@ -246,10 +297,13 @@
|
|||
|
||||
- name: test state=import to restore a database from multiple database dumped file2
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: import
|
||||
target: '{{ dump_file2 }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: import_result2
|
||||
|
||||
- name: assert output message restored a database from dump file2
|
||||
|
@ -259,7 +313,7 @@
|
|||
- import_result2.db_list == ['{{ db_name2 }}']
|
||||
|
||||
- name: run command to list databases
|
||||
command: mysql "-e show databases like 'data%';"
|
||||
command: "{{ mysql_command }} \"-e show databases like 'data%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that db_name2 database does exist after import
|
||||
|
@ -269,48 +323,58 @@
|
|||
|
||||
- name: test state=dump to backup the database of type {{ format_type }} (expect changed=true)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: dump
|
||||
target: '{{ db_file_name }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message backup the database
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "result.db =='{{ db_name }}'"
|
||||
- "result.changed == true"
|
||||
- "result.db =='{{ db_name }}'"
|
||||
|
||||
- name: assert database was backed up successfully
|
||||
command: file {{ db_file_name }}
|
||||
register: result
|
||||
|
||||
- name: assert file format type
|
||||
assert: { that: "'{{format_msg_type}}' in result.stdout" }
|
||||
# - name: assert database was backed up successfully
|
||||
# command: "file {{ db_file_name }}"
|
||||
# register: result
|
||||
#
|
||||
# - name: assert file format type
|
||||
# assert:
|
||||
# that:
|
||||
# - "'{{ format_msg_type }}' in result.stdout"
|
||||
|
||||
- name: update database table employee
|
||||
command: mysql {{ db_name }} "-e update employee set name='John Doe' where id=47;"
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e update employee set name='John Doe' where id=47\""
|
||||
|
||||
- name: test state=import to restore the database of type {{ format_type }} (expect changed=true)
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: import
|
||||
target: '{{ db_file_name }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message restore the database
|
||||
assert: { that: "result.changed == true" }
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: select data from table employee
|
||||
command: mysql {{ db_name }} "-e select * from employee;"
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e select * from employee\""
|
||||
register: result
|
||||
|
||||
- name: assert data in database is from the restore database
|
||||
assert:
|
||||
that:
|
||||
- "'47' in result.stdout"
|
||||
- "'Joe Smith' in result.stdout"
|
||||
- "'47' in result.stdout"
|
||||
- "'Joe Smith' in result.stdout"
|
||||
|
||||
##########################
|
||||
# Test ``force`` parameter
|
||||
|
@ -321,30 +385,36 @@
|
|||
|
||||
- name: try to import without force parameter, must fail
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: import
|
||||
target: '{{ wrong_sql_file }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
force: no
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.failed == true
|
||||
- result.failed == true
|
||||
|
||||
- name: try to import with force parameter
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: import
|
||||
target: '{{ wrong_sql_file }}'
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
force: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result is changed
|
||||
|
||||
##########
|
||||
# Clean up
|
||||
|
@ -352,24 +422,38 @@
|
|||
|
||||
- name: remove database name
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: absent
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
|
||||
- name: remove file name
|
||||
file: name={{ db_file_name }} state=absent
|
||||
file:
|
||||
name: '{{ db_file_name }}'
|
||||
state: absent
|
||||
|
||||
- name: remove file name
|
||||
file: name={{ wrong_sql_file }} state=absent
|
||||
file:
|
||||
name: '{{ wrong_sql_file }}'
|
||||
state: absent
|
||||
|
||||
- name: remove dump file1
|
||||
file: name={{ dump_file1 }} state=absent
|
||||
file:
|
||||
name: '{{ dump_file1 }}'
|
||||
state: absent
|
||||
|
||||
- name: remove dump file2
|
||||
file: name={{ dump_file2 }} state=absent
|
||||
file:
|
||||
name: '{{ dump_file2 }}'
|
||||
state: absent
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
# defaults file for test_mysql_info
|
||||
mysql_user: root
|
||||
mysql_password: msandbox
|
||||
mysql_host: 127.0.0.1
|
||||
mysql_primary_port: 3307
|
||||
|
||||
db_name: data
|
|
@ -1,3 +1,3 @@
|
|||
dependencies:
|
||||
- setup_mysql_db
|
||||
- setup_mysql
|
||||
- setup_remote_tmp_dir
|
186
tests/integration/targets/test_mysql_info/tasks/main.yml
Normal file
186
tests/integration/targets/test_mysql_info/tasks/main.yml
Normal file
|
@ -0,0 +1,186 @@
|
|||
# Test code for mysql_info module
|
||||
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
###################
|
||||
# Prepare for tests
|
||||
#
|
||||
|
||||
- vars:
|
||||
mysql_parameters: &mysql_params
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
|
||||
block:
|
||||
|
||||
# Create default MySQL config file with credentials
|
||||
- name: mysql_info - create default config file
|
||||
template:
|
||||
src: my.cnf.j2
|
||||
dest: /root/.my.cnf
|
||||
mode: '0400'
|
||||
|
||||
# Create non-default MySQL config file with credentials
|
||||
- name: mysql_info - create non-default config file
|
||||
template:
|
||||
src: my.cnf.j2
|
||||
dest: /root/non-default_my.cnf
|
||||
mode: '0400'
|
||||
|
||||
###############
|
||||
# Do tests
|
||||
|
||||
# Access by default cred file
|
||||
- name: mysql_info - collect default cred file
|
||||
mysql_info:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
- result.settings != {}
|
||||
- result.global_status != {}
|
||||
- result.databases != {}
|
||||
- result.engines != {}
|
||||
- result.users != {}
|
||||
|
||||
# Access by non-default cred file
|
||||
- name: mysql_info - check non-default cred file
|
||||
mysql_info:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
config_file: /root/non-default_my.cnf
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
|
||||
# Remove cred files
|
||||
- name: mysql_info - remove cred files
|
||||
file:
|
||||
path: '{{ item }}'
|
||||
state: absent
|
||||
with_items:
|
||||
- /root/.my.cnf
|
||||
- /root/non-default_my.cnf
|
||||
|
||||
# Access with password
|
||||
- name: mysql_info - check access with password
|
||||
mysql_info:
|
||||
<<: *mysql_params
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
|
||||
# Test excluding
|
||||
- name: Collect all info except settings and users
|
||||
mysql_info:
|
||||
<<: *mysql_params
|
||||
filter: '!settings,!users'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
- result.global_status != {}
|
||||
- result.databases != {}
|
||||
- result.engines != {}
|
||||
- result.settings is not defined
|
||||
- result.users is not defined
|
||||
|
||||
# Test including
|
||||
- name: Collect info only about version and databases
|
||||
mysql_info:
|
||||
<<: *mysql_params
|
||||
filter:
|
||||
- version
|
||||
- databases
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.version != {}
|
||||
- result.databases != {}
|
||||
- result.engines is not defined
|
||||
- result.settings is not defined
|
||||
- result.global_status is not defined
|
||||
- result.users is not defined
|
||||
|
||||
# Test exclude_fields: db_size
|
||||
# 'unsupported' element is passed to check that an unsupported value
|
||||
# won't break anything (will be ignored regarding to the module's documentation).
|
||||
- name: Collect info about databases excluding their sizes
|
||||
mysql_info:
|
||||
<<: *mysql_params
|
||||
filter:
|
||||
- databases
|
||||
exclude_fields:
|
||||
- db_size
|
||||
- unsupported
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.databases != {}
|
||||
- result.databases.mysql == {}
|
||||
|
||||
########################################################
|
||||
# Issue #65727, empty databases must be in returned dict
|
||||
#
|
||||
- name: Create empty database acme
|
||||
mysql_db:
|
||||
<<: *mysql_params
|
||||
name: acme
|
||||
|
||||
- name: Collect info about databases
|
||||
mysql_info:
|
||||
<<: *mysql_params
|
||||
filter:
|
||||
- databases
|
||||
return_empty_dbs: true
|
||||
register: result
|
||||
|
||||
# Check acme is in returned dict
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.databases.acme.size == 0
|
||||
- result.databases.mysql != {}
|
||||
|
||||
- name: Collect info about databases excluding their sizes
|
||||
mysql_info:
|
||||
<<: *mysql_params
|
||||
filter:
|
||||
- databases
|
||||
exclude_fields:
|
||||
- db_size
|
||||
return_empty_dbs: true
|
||||
register: result
|
||||
|
||||
# Check acme is in returned dict
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
- result.databases.acme == {}
|
||||
- result.databases.mysql == {}
|
||||
|
||||
- name: Remove acme database
|
||||
mysql_db:
|
||||
<<: *mysql_params
|
||||
name: acme
|
||||
state: absent
|
|
@ -0,0 +1,5 @@
|
|||
[client]
|
||||
user={{ mysql_user }}
|
||||
password={{ mysql_password }}
|
||||
host={{ mysql_host }}
|
||||
port={{ mysql_primary_port }}
|
|
@ -1,4 +1,7 @@
|
|||
root_user: root
|
||||
mysql_user: root
|
||||
mysql_password: msandbox
|
||||
mysql_primary_port: 3307
|
||||
|
||||
db_name: data
|
||||
test_db: testdb
|
||||
test_table1: test1
|
2
tests/integration/targets/test_mysql_query/meta/main.yml
Normal file
2
tests/integration/targets/test_mysql_query/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- setup_mysql
|
|
@ -0,0 +1,2 @@
|
|||
# mysql_query module initial CI tests
|
||||
- import_tasks: mysql_query_initial.yml
|
|
@ -3,9 +3,10 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
- vars:
|
||||
mysql_parameters: &mysql_params
|
||||
login_unix_socket: '{{ mysql_socket }}'
|
||||
login_user: '{{ root_user }}'
|
||||
login_password: '{{ root_pass }}'
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
|
||||
block:
|
||||
|
|
@ -1,5 +1,10 @@
|
|||
---
|
||||
# defaults file for test_mysql_user
|
||||
mysql_user: root
|
||||
mysql_password: msandbox
|
||||
mysql_host: 127.0.0.1
|
||||
mysql_primary_port: 3307
|
||||
|
||||
db_name: 'data'
|
||||
user_name_1: 'db_user1'
|
||||
user_name_2: 'db_user2'
|
|
@ -1,6 +1,6 @@
|
|||
USE foo;
|
||||
DELIMITER ;;
|
||||
CREATE FUNCTION `function` () RETURNS tinyint(4)
|
||||
CREATE FUNCTION `function` () RETURNS tinyint(4) DETERMINISTIC
|
||||
BEGIN
|
||||
DECLARE NAME_FOUND tinyint DEFAULT 0;
|
||||
RETURN NAME_FOUND;
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue