mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-06 10:40:36 -07:00
Apply suggestions from code review
Co-authored-by: Laurent Indermühle <laurent.indermuehle@pm.me>
This commit is contained in:
parent
379b25e8fa
commit
682fae4125
3 changed files with 21 additions and 40 deletions
|
@ -481,9 +481,8 @@ def main():
|
||||||
module.fail_json(msg="password_expire value interval \
|
module.fail_json(msg="password_expire value interval \
|
||||||
should be used with password_expire_interval")
|
should be used with password_expire_interval")
|
||||||
|
|
||||||
if password_expire_interval:
|
if password_expire_interval and password_expire_interval < 1:
|
||||||
if password_expire_interval < 1:
|
module.fail_json(msg="password_expire_interval value \
|
||||||
module.fail_json(msg="password_expire_interval value \
|
|
||||||
should be positive number")
|
should be positive number")
|
||||||
|
|
||||||
cursor = None
|
cursor = None
|
||||||
|
|
|
@ -118,7 +118,7 @@
|
||||||
expected_password_expired: "N"
|
expected_password_expired: "N"
|
||||||
|
|
||||||
- name: password_expire | Set password_expire = interval without password_expire_interval
|
- name: password_expire | Set password_expire = interval without password_expire_interval
|
||||||
mysql_user:
|
community.mysql.mysql_user:
|
||||||
<<: *mysql_params
|
<<: *mysql_params
|
||||||
name: '{{ user_name_4 }}'
|
name: '{{ user_name_4 }}'
|
||||||
host: '%'
|
host: '%'
|
||||||
|
@ -129,13 +129,13 @@
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: password_expire | Assert that action fails if 'password_expire_interval' not set
|
- name: password_expire | Assert that action fails if 'password_expire_interval' not set
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is failed
|
- result is failed
|
||||||
- "'should be used with' in result.msg"
|
- "'should be used with' in result.msg"
|
||||||
|
|
||||||
- name: password_expire | Set password_expire_interval < 1
|
- name: password_expire | Set password_expire_interval < 1
|
||||||
mysql_user:
|
community.mysql.mysql_user:
|
||||||
<<: *mysql_params
|
<<: *mysql_params
|
||||||
name: '{{ user_name_4 }}'
|
name: '{{ user_name_4 }}'
|
||||||
host: '%'
|
host: '%'
|
||||||
|
@ -147,13 +147,13 @@
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: password_expire | Assert that action fails if 'password_expire_interval' is < 1
|
- name: password_expire | Assert that action fails if 'password_expire_interval' is < 1
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is failed
|
- result is failed
|
||||||
- "'should be positive number' in result.msg"
|
- "'should be positive number' in result.msg"
|
||||||
|
|
||||||
- name: password_expire | check mode for user creation
|
- name: password_expire | check mode for user creation
|
||||||
mysql_user:
|
community.mysql.mysql_user:
|
||||||
<<: *mysql_params
|
<<: *mysql_params
|
||||||
name: '{{ user_name_4 }}'
|
name: '{{ user_name_4 }}'
|
||||||
host: '%'
|
host: '%'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
- name: Utils | Assert user password_expire | Create modify {{ username }} with password_expire
|
- name: Utils | Assert user password_expire | Create modify {{ username }} with password_expire
|
||||||
mysql_user:
|
community.mysql.mysql_user:
|
||||||
login_user: "{{ mysql_parameters.login_user }}"
|
login_user: "{{ mysql_parameters.login_user }}"
|
||||||
login_password: "{{ mysql_parameters.login_password }}"
|
login_password: "{{ mysql_parameters.login_password }}"
|
||||||
login_host: "{{ mysql_parameters.login_host }}"
|
login_host: "{{ mysql_parameters.login_host }}"
|
||||||
|
@ -13,32 +13,25 @@
|
||||||
password_expire_interval: "{{ password_expire_interval | default(omit) }}"
|
password_expire_interval: "{{ password_expire_interval | default(omit) }}"
|
||||||
register: result
|
register: result
|
||||||
check_mode: "{{ check_mode | default(false) }}"
|
check_mode: "{{ check_mode | default(false) }}"
|
||||||
|
failed_when: result.changed != expect_change_value
|
||||||
- name: Utils | Assert user password_expire | Assert a change occurred
|
|
||||||
assert:
|
|
||||||
that: result.changed == expect_change_value
|
|
||||||
vars:
|
vars:
|
||||||
expect_change_value: "{{ expect_change }}"
|
expect_change_value: "{{ expect_change }}"
|
||||||
|
|
||||||
- name: Utils | Assert user password_lifetime | Query user '{{ username }}'
|
- name: Utils | Assert user password_lifetime | Query user '{{ username }}'
|
||||||
command: '{{ mysql_command }} -BNe "SELECT IFNULL(password_lifetime, -1) FROM mysql.user where user=''{{ username }}'' and host=''{{ host }}''"'
|
ansible.builtin.command:
|
||||||
|
cmd: >
|
||||||
|
{{ mysql_command }} -BNe "SELECT IFNULL(password_lifetime, -1)
|
||||||
|
FROM mysql.user where user='{{ username }}' and host='{{ host }}'"
|
||||||
register: password_lifetime
|
register: password_lifetime
|
||||||
when:
|
when:
|
||||||
- db_engine == 'mysql'
|
- db_engine == 'mysql'
|
||||||
- db_version is version('5.7.0', '>=')
|
- db_version is version('5.7.0', '>=')
|
||||||
|
failed_when: expected_password_lifetime_value not in password_lifetime.stdout_lines
|
||||||
- name: Utils | Assert user password_lifetime | Assert password_lifetime is in user stdout
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- expected_password_lifetime_value in password_lifetime.stdout_lines
|
|
||||||
vars:
|
vars:
|
||||||
expected_password_lifetime_value: "{{ expected_password_lifetime }}"
|
expected_password_lifetime_value: "{{ expected_password_lifetime }}"
|
||||||
when:
|
|
||||||
- db_engine == 'mysql'
|
|
||||||
- db_version is version('5.7.0', '>=')
|
|
||||||
|
|
||||||
- name: Utils | Assert user password_lifetime | Query user '{{ username }}'
|
- name: Utils | Assert user password_lifetime | Query user '{{ username }}'
|
||||||
command:
|
ansible.builtin.command:
|
||||||
"{{ mysql_command }} -BNe \"SELECT JSON_EXTRACT(Priv, '$.password_lifetime') AS password_lifetime \
|
"{{ mysql_command }} -BNe \"SELECT JSON_EXTRACT(Priv, '$.password_lifetime') AS password_lifetime \
|
||||||
FROM mysql.global_priv \
|
FROM mysql.global_priv \
|
||||||
WHERE user='{{ username }}' and host='{{ host }}'\""
|
WHERE user='{{ username }}' and host='{{ host }}'\""
|
||||||
|
@ -46,29 +39,18 @@
|
||||||
when:
|
when:
|
||||||
- db_engine == 'mariadb'
|
- db_engine == 'mariadb'
|
||||||
- db_version is version('10.4.3', '>=')
|
- db_version is version('10.4.3', '>=')
|
||||||
|
failed_when: expected_password_lifetime_value not in password_lifetime.stdout_lines
|
||||||
- name: Utils | Assert user password_lifetime | Assert password_lifetime is in user stdout
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- expected_password_lifetime_value in password_lifetime.stdout_lines
|
|
||||||
vars:
|
vars:
|
||||||
expected_password_lifetime_value: "{{ expected_password_lifetime }}"
|
expected_password_lifetime_value: "{{ expected_password_lifetime }}"
|
||||||
when:
|
|
||||||
- db_engine == 'mariadb'
|
|
||||||
- db_version is version('10.4.3', '>=')
|
|
||||||
|
|
||||||
- name: Utils | Assert user password_expired | Query user '{{ username }}'
|
- name: Utils | Assert user password_expired | Query user '{{ username }}'
|
||||||
command: "{{ mysql_command }} -BNe \"SELECT password_expired FROM mysql.user \
|
ansible.builtin.command:
|
||||||
WHERE user='{{ username }}' and host='{{ host }}'\""
|
cmd: >
|
||||||
|
{{ mysql_command }} -BNe "SELECT password_expired FROM mysql.user
|
||||||
|
WHERE user='{{ username }}' and host='{{ host }}'"
|
||||||
register: password_expired
|
register: password_expired
|
||||||
when: (db_engine == 'mysql' and db_version is version('5.7.0', '>=')) or
|
when: (db_engine == 'mysql' and db_version is version('5.7.0', '>=')) or
|
||||||
(db_engine == 'mariadb' and db_version is version('10.4.3', '>='))
|
(db_engine == 'mariadb' and db_version is version('10.4.3', '>='))
|
||||||
|
failed_when: expected_password_expired_value not in password_expired.stdout_lines
|
||||||
- name: Utils | Assert user password_expired | Assert password_expired is in user stdout
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- expected_password_expired_value in password_expired.stdout_lines
|
|
||||||
vars:
|
vars:
|
||||||
expected_password_expired_value: "{{ expected_password_expired }}"
|
expected_password_expired_value: "{{ expected_password_expired }}"
|
||||||
when: (db_engine == 'mysql' and db_version is version('5.7.0', '>=')) or
|
|
||||||
(db_engine == 'mariadb' and db_version is version('10.4.3', '>='))
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue