summaryrefslogtreecommitdiff
path: root/test/integration/targets/mysql_variables/tasks/main.yml
blob: 26fc03c8679ab50e2211849db24a23bed4bd104a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# 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}}
  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}}

- name: update mysql variable to same value (expect changed=false)
  mysql_variables: variable={{set_name}} value={{set_value}}
  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'

- name: update mysql variable value (expect changed=true)
  mysql_variables: variable={{set_name}} value={{set_value}}
  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 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"

- name: update mysql variable value (expect changed=true)
  mysql_variables: variable={{set_name}} value={{set_value}}
  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

- name: update mysql variable value (expect changed=true)
  mysql_variables: variable={{set_name}} value={{set_value}}
  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"
  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
  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
  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
  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
  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

- 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'

- name: remove mysql_user {{user}}
  mysql_user: name={{user}} state=absent

#============================================================
# 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 connect_timeout=5
  register: result
  ignore_errors: true

- include: assert_fail_msg.yml output={{result}}  msg='unable to connect to database'