Unable to make my idempotent MySQL playbook to work

Hi,

I’m having a very hard time making my MySQL playbook idemptotent on my vagrant dev machine. I came across two posts from Lorin Hochstein, but unfortunately i’m still getting the error ‘msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials’ after running the playbook.

At this point I’m clueless on how to proceed since my MySQL playbook is (almost) exactly the same like the one proposed in the SO answer at the link below.

I’ve uploaded the playbook, together with the Vagrantfile and host file on github: https://github.com/SjorsB/Apache-with-Nginx-Reverse-Proxy-Ansible-Playbook

Any help is greatly appreciated.

Regards,

Sjors

I was having the same issue.

I’m using the same playbook as the stackoverflow link you provided, the only thing I updated from it to make it work for me was moving the task that writes “/root/.my.cnf” before the task that updates the root password for all accounts.

This is how my playbook looks like…

`

  • name: ensure mysql is running and starts on boot
    service: name=mysql state=started enabled=true

  • name: copy .my.cnf file with root password credentials
    template: src=root-my-cnf.j2 dest=/root/.my.cnf owner=root mode=0600

‘localhost’ needs to be the last item for idempotency, see

http://ansible.cc/docs/modules.html#mysql-user

  • name: update mysql root password for all root accounts
    mysql_user: name=root host={{ item }} password={{ mysql_root_password }} priv=.:ALL,GRANT
    with_items:

  • “{{ ansible_hostname }}”

  • 127.0.0.1

  • ::1

  • localhost

  • name: ensure anonymous users are not in the database
    mysql_user: name=‘’ host={{ item }} state=absent
    with_items:

  • “{{ ansible_hostname }}”

  • 127.0.0.1

  • ::1

  • localhost

  • name: remove the test database
    mysql_db: name=test state=absent

`

Might be worth taking a look at the mysql role in Ansible galaxy.