Unable to make my idempotent MySQL playbook to work

661 views
Skip to first unread message

Sjors Buitenhuis

unread,
Jan 5, 2014, 5:44:08 AM1/5/14
to ansible...@googlegroups.com
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

Ricardo Pérez Porras

unread,
Mar 11, 2014, 12:13:28 PM3/11/14
to ansible...@googlegroups.com
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
- 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

James Martin

unread,
Mar 11, 2014, 8:16:00 PM3/11/14
to ansible...@googlegroups.com

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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages