bertvv / ansible-role-mariadb

Install MariaDB on RHEL/CentOS 7 or Fedora.
https://galaxy.ansible.com/bertvv/mariadb/
Other
144 stars 108 forks source link

"Set MariaDB root password for the first time" task fails #32

Closed nhenderson closed 4 years ago

nhenderson commented 4 years ago

Summary

The Set MariaDB root password for the first time (root@localhost) task fails when a username and password is set for mysqladmin in the custom.cnf file.

Steps to reproduce

  1. Add the following variable to the playbook:
mariadb_custom_cnf:
  mysqladmin:
    user: root
    password: <redacted>

NOTE: Make sure to update <redacted> with your root password.

  1. Run the playbook:
    ansible-playbook playbooks/provision-mariadb-dbs.yml
  2. Run the playbook again to check for idempotentcy. (I believe the error happens on the first run, but it will definitely happen on the second run after the root password is set.)

What is the current bug behavior?

An error message displays on the run of the playbook.

What is the expected correct behavior?

The playbook should succeed on every run of the playbook, even if the root password for mysqladmin is set in a .cnf config file.

Relevant logs and/or screenshots

The Check if root password is set task erroneously succeeds. (A root password is set, but this command still succeeds.

mysqladmin -u root status

The following task, Set MariaDB root password for the first time (root@localhost) fails because a password as already been set:

msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (1045, \"Access denied for user 'root'@'localhost' (using password: NO)\")"

Possible fixes

Please update the following task to detect if a root password is set without using the mysqladmin command:

# This command will succeed when the root password was set previously
- name: Check if root password is set
  shell: >
    mysql -u root
    -p'{{ mariadb_root_password }}'
    -h localhost
    -S {{ mariadb_socket }}
    -e "quit"
  changed_when: false
  ignore_errors: true
  register: root_pwd_check
  tags: mariadb

Also change the conditionals in these two lines: line 28 line 43

to:

when: root_pwd_check.rc != 0

I will make a merge request for this change shortly.

bertvv commented 4 years ago

I merged the PR so will close this issue. Thank you for fixing this!