Last active
January 4, 2016 05:49
-
-
Save hyperfocus1338/8577582 to your computer and use it in GitHub Desktop.
Idempotent MySQL example which fails to create a database gives error: msg: unable to connect, check login_user and login_password are correct, or alternatively check ~/.my.cnf contains credentials tail -f /var/log/mysql/mysql.log on the host only tells me: 51 Connect root@localhost on website (website is database name)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: install MySQL | |
apt: pkg={{ item }} | |
state=present | |
update_cache=yes | |
with_items: | |
- python-mysqldb | |
- mysql-client | |
- mysql-server | |
- mysql-common | |
notify: start mysql | |
- name: update mysql root password for all root accounts | |
mysql_user: name={{ mysql_root_user }} | |
host={{ item }} | |
password={{ mysql_root_password }} | |
with_items: | |
- "{{ ansible_hostname }}" | |
- 127.0.0.1 | |
- ::1 | |
- localhost | |
- name: copy my.cnf file with root password credentials | |
template: src=my.cnf.j2 | |
dest=/root/.my.cnf | |
owner=root | |
group=root | |
mode=0600 | |
- name: delete the MySQL test database | |
mysql_db: db="test" | |
state="absent" | |
- name: delete anonymous MySQL server user for localhost | |
mysql_user: user="" | |
state="absent" | |
- name: delete anonymous MySQL server user for servername | |
mysql_user: user="" | |
host="{{ ansible_hostname }}" | |
state="absent" | |
notify: restart mysql | |
- name: make website database | |
mysql_db: name=website | |
login_user={{ mysql_root_user }} | |
login_password={{ mysql_root_password }} | |
state=present | |
- name: import website database | |
mysql_db: name=website | |
login_user={{ mysql_root_user }} | |
login_password={{ mysql_root_password }} | |
target=database.sql | |
state=import |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment