-2

Geting error while connecting to remote Mysql host using Ansible.

Playbook as below

--- 
- name: "Create database"
  login_host: host.xyz.com 
  login_password: "{{ mysql_root_pass }}"
  login_port: "{{ mysql_port }}"
  login_user: "{{ mysql_root }}"
  mysql_db: "db=\"{{ item }}\" state=present"

When try to connect getting following error.

"msg": "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)\n"
sanjayparmar
  • 623
  • 8
  • 18

2 Answers2

1

The error tells you exactly what it is - you cannot connect to the mySQL server on the host that you are running the mySQL command. Chances are it is one or more of the following:

  1. mySQL server is not running.
  2. mySQL server is up, but does not have a DNS entry.
  3. mySQL server is up, but it is on the different network, so it is not routable from the host you are running the mySQL command on.
  4. mySQL server is up, but firewall rules are preventing you from connecting to it from the host you are running the mySQL command on.
Rilindo
  • 5,058
  • 5
  • 26
  • 46
  • Mysql Server is up and running. Its AWS RDS and I am able to connect manually but not from Ansible playbook. It seems issue with Ansible. – sanjayparmar Apr 23 '18 at 15:44
  • Connect manually from the remote host or from your control master? Based on the docs [here](http://docs.ansible.com/ansible/latest/modules/mysql_db_module.html), the mysqldb module seems to run the command from the remote host, which is where you need to verify that the database is reachable. – Rilindo Apr 23 '18 at 16:26
0

it was due to syntax .

Correct is below -

---
- name: Create database
  mysql_db:
    login_host: test.xyz.com
    login_password: "{{ mysql_root_pass }}"
    login_port: "{{ mysql_port }}"
    login_user: "{{ mysql_root }}"
sanjayparmar
  • 623
  • 8
  • 18