My task throws an error as follows:
TASK [mysql : Update MySQL root password for all root accounts] ************************************************************************
failed: [1.2.3.4] (item=127.0.0.1) => {"changed": false, "item": "127.0.0.1", "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (1045, \"Access denied for user 'root'@'localhost' (using password: YES)\")"}
failed: [1.2.3.4] (item=::1) => {"changed": false, "item": "::1", "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (1045, \"Access denied for user 'root'@'localhost' (using password: YES)\")"}
failed: [1.2.3.4] (item=localhost) => {"changed": false, "item": "localhost", "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (1045, \"Access denied for user 'root'@'localhost' (using password: YES)\")"}
If I remote into the user using the user 'deploy' I can do the following just fine:
mysql -h 127.0.0.1 -u root -p
And it logs into the mysql server.
Why is it having an issue with ansible doing it?
my main yml file is doing this:
remote_user: deploy
become: yes
become_method: sudo
gather_facts: no
mysql/tasks/main.yml is:
---
- name: Install MySQL
apt: name={{ item }} state=latest update_cache=true
with_items:
- python-mysqldb
- mysql-server
- mysql-client
- libmysqlclient-dev
- name: Ensure MySQL service is up
service: name=mysql state=started
- name: copy .my.cnf file with root password credentials
template:
src=templates/my.cnf
dest=/root/.my.cnf
owner=root
mode=0600
- name: Update MySQL root password for all root accounts
mysql_user: name=root
host={{ item }}
password={{ mysql_root_db_password }}
with_items:
- 127.0.0.1
- ::1
- localhost
- name: Ensure anonymous users are not in the database
mysql_user: name='' host={{ item }} state=absent
with_items:
- $inventory_hostname
- $ansible_hostname
- localhost
- name: Create MySQL Database
mysql_db: name={{ deploy_app_name }}
state=present
encoding=utf8mb4
- name: Create MySQL User
mysql_user: name={{ deploy_app_name }}
priv={{ deploy_app_name }}.*:ALL
state=present
password="{{ mysql_app_db_password }}"