Changing MySQL's root password in Ansible

  • Fri 17 June 2016
  • misc

Ansible's docs are pretty good, but their mysql_user: module documentation is a little short on a good example for changing the mysql root user's password. Naively following a randomly picked example will result in a root user without the GRANT privilege (with ensuing horrible confusion), or possibly not being able to log into root because confusion about the difference between $hostname and localhost.

Here's a config snippet that works:

{% raw %} - mysql_user: name=root password=obviouspw priv=.:ALL,GRANT host={{ item }} state=present with_items: - "{{ ansible_hostname }}" - - ::1 - localhost

{% endraw %}

Or you could decide to not run MySQL, but that's a discussion for a different day.