diff --git a/plugins/modules/mysql_user.py b/plugins/modules/mysql_user.py index 24b9612..82cfcb9 100644 --- a/plugins/modules/mysql_user.py +++ b/plugins/modules/mysql_user.py @@ -481,9 +481,8 @@ def main(): module.fail_json(msg="password_expire value interval \ should be used with password_expire_interval") - if password_expire_interval: - if password_expire_interval < 1: - module.fail_json(msg="password_expire_interval value \ + if password_expire_interval and password_expire_interval < 1: + module.fail_json(msg="password_expire_interval value \ should be positive number") cursor = None diff --git a/tests/integration/targets/test_mysql_user/tasks/test_password_expire.yml b/tests/integration/targets/test_mysql_user/tasks/test_password_expire.yml index 5605f07..ead2a6d 100644 --- a/tests/integration/targets/test_mysql_user/tasks/test_password_expire.yml +++ b/tests/integration/targets/test_mysql_user/tasks/test_password_expire.yml @@ -118,7 +118,7 @@ expected_password_expired: "N" - name: password_expire | Set password_expire = interval without password_expire_interval - mysql_user: + community.mysql.mysql_user: <<: *mysql_params name: '{{ user_name_4 }}' host: '%' @@ -129,13 +129,13 @@ ignore_errors: true - name: password_expire | Assert that action fails if 'password_expire_interval' not set - assert: + ansible.builtin.assert: that: - result is failed - "'should be used with' in result.msg" - name: password_expire | Set password_expire_interval < 1 - mysql_user: + community.mysql.mysql_user: <<: *mysql_params name: '{{ user_name_4 }}' host: '%' @@ -147,13 +147,13 @@ ignore_errors: true - name: password_expire | Assert that action fails if 'password_expire_interval' is < 1 - assert: + ansible.builtin.assert: that: - result is failed - "'should be positive number' in result.msg" - name: password_expire | check mode for user creation - mysql_user: + community.mysql.mysql_user: <<: *mysql_params name: '{{ user_name_4 }}' host: '%' diff --git a/tests/integration/targets/test_mysql_user/tasks/utils/assert_user_password_expire.yml b/tests/integration/targets/test_mysql_user/tasks/utils/assert_user_password_expire.yml index b1d3579..3798802 100644 --- a/tests/integration/targets/test_mysql_user/tasks/utils/assert_user_password_expire.yml +++ b/tests/integration/targets/test_mysql_user/tasks/utils/assert_user_password_expire.yml @@ -1,6 +1,6 @@ --- - 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_password: "{{ mysql_parameters.login_password }}" login_host: "{{ mysql_parameters.login_host }}" @@ -13,32 +13,25 @@ password_expire_interval: "{{ password_expire_interval | default(omit) }}" register: result check_mode: "{{ check_mode | default(false) }}" - -- name: Utils | Assert user password_expire | Assert a change occurred - assert: - that: result.changed == expect_change_value + failed_when: result.changed != expect_change_value vars: expect_change_value: "{{ expect_change }}" - 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 when: - db_engine == 'mysql' - db_version is version('5.7.0', '>=') - -- name: Utils | Assert user password_lifetime | Assert password_lifetime is in user stdout - assert: - that: - - expected_password_lifetime_value in password_lifetime.stdout_lines + failed_when: expected_password_lifetime_value not in password_lifetime.stdout_lines vars: 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 }}' - command: + ansible.builtin.command: "{{ mysql_command }} -BNe \"SELECT JSON_EXTRACT(Priv, '$.password_lifetime') AS password_lifetime \ FROM mysql.global_priv \ WHERE user='{{ username }}' and host='{{ host }}'\"" @@ -46,29 +39,18 @@ when: - db_engine == 'mariadb' - db_version is version('10.4.3', '>=') - -- name: Utils | Assert user password_lifetime | Assert password_lifetime is in user stdout - assert: - that: - - expected_password_lifetime_value in password_lifetime.stdout_lines + failed_when: expected_password_lifetime_value not in password_lifetime.stdout_lines vars: 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 }}' - command: "{{ mysql_command }} -BNe \"SELECT password_expired FROM mysql.user \ - WHERE user='{{ username }}' and host='{{ host }}'\"" + ansible.builtin.command: + cmd: > + {{ mysql_command }} -BNe "SELECT password_expired FROM mysql.user + WHERE user='{{ username }}' and host='{{ host }}'" register: 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', '>=')) - -- name: Utils | Assert user password_expired | Assert password_expired is in user stdout - assert: - that: - - expected_password_expired_value in password_expired.stdout_lines + failed_when: expected_password_expired_value not in password_expired.stdout_lines vars: 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', '>='))