---
- name: Install mysql using yum
action: yum pkg={{item}} state=latest
with_items:
- MySQL-python
- mysql
- mysql-server
- name: Start the mysql server
service: name=mysqld state=running enabled=yes
- name: copy .my.cnf file with root password credentials
template: src=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 }}
with_items:
- '{{ ansible_hostname }}'
- 127.0.0.1
- ::1
- localhost
- name: delete anonymous MySQL server user for $server_hostname
action: mysql_user user="" host="$server_hostname" state="absent"
- name: delete anonymous MySQL server user for localhost
action: mysql_user user="" state="absent"
- name: remove the MySQL test database
action: mysql_db db=test state=absent
My cnf file is -
$cat roles/database/templates/.my.cnf.j2
[client]
user=root
password={{ mysql_root_password }}
and My variable file is -
$cat roles/database/vars/main.yml
user: root
mysql_root_password: *******
But when I run the playbook, I am getting the following error.
msg: unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials
I am doing exactly the same as mentioned in the above 2 links. I even tried to perform the conf file copy task before root password change task. But I am still unable to run it successfully.
I would really appreciate any kind of help.
Thanks,
Chinmaya