Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the "Check if root password is set" task logic #33

Merged
merged 1 commit into from
Jun 12, 2020
Merged

Update the "Check if root password is set" task logic #33

merged 1 commit into from
Jun 12, 2020

Conversation

nhenderson
Copy link

This is a fix for the following problem:

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

See issue 32

@bertvv bertvv merged commit 9aae160 into bertvv:master Jun 12, 2020
@bertvv
Copy link
Owner

bertvv commented Jun 12, 2020

Thanks for the addition!

@grahamrhay grahamrhay mentioned this pull request Nov 5, 2020
@chrisdeeming
Copy link

chrisdeeming commented Nov 11, 2020

Just want to highlight that this change caused a regression. Please see #46 for info. I've patched this change out to get things working normally but this likely needs to be revisited @bertvv @nhenderson.

@angwe
Copy link

angwe commented Dec 3, 2020

# This command will exit non-zero when the root password was set previously
- name: Check if root password is unset
  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

# Repeat runs with the same password can continue idempotently, otherwise fail.
- name: Check if the specified root password is already set
  shell: >
    mysqladmin -u root -p{{ mariadb_root_password }} status
  changed_when: false
  no_log: true
  when: root_pwd_check.rc != 0
  tags: mariadb

This will ALWAYS fail when the password is currently unset, as both tasks try to use a password.

The password doesn't get set until a task at the end of the root-passwords task list.

I see what the task is trying to do - make sure that the user is not trying to change the root password with the role - but it also stops the role from working correctly.

@angwe
Copy link

angwe commented Dec 3, 2020

# This command will exit non-zero when the root password was set previously or if it is still blank
- name: Check if root password is set already
  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

# This command will exit non-zero if the root password was set but not if is still blank
- name: Check if root password is blank
  shell: >
    mysql -u root
    -h localhost
    -S {{ mariadb_socket }}
    -e "quit"
  changed_when: false
  ignore_errors: true
  when: root_pwd_check.rc != 0
  register: root_pwd_blank
  tags: mariadb

# Repeat runs with the same password can continue idempotently, otherwise fail.
- name: Check if the specified root password is already set
  shell: >
    mysqladmin -u root -p{{ mariadb_root_password }} status
  changed_when: false
  no_log: true
  when:
    - root_pwd_check.rc != 0
    - root_pwd_blank.rc != 0
  tags: mariadb

- name: Check for previously set unix_socket in plugin column
  command: >
    mysql -N -s -p'{{ mariadb_root_password }}' -S {{ mariadb_socket }} -u root -e
    "SELECT plugin from mysql.user WHERE user = 'root'"
  register: plugin_root_result
  changed_when: plugin_root_result.stdout is search('unix_socket')
  when: root_pwd_check.rc == 0
  tags: mariadb

That seems to have solved my problem and still allowed the logic to be as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants