I am new to ansible i want to execute my command like this

zcat /usr/share/doc/zabbix-server-mysql-3.0.9/create.sql.gz| mysql -u zabbix -p zabbixdb

Ansible_code:

- name: Import the initial schema
  mysql_db:
          state: import
          login_user: zabbix
          login_password: 1234
          name: zabbixdb
          target: /usr/share/doc/zabbix-server-mysql-3.0.9/create.sql.gz
  run_once: true

Output_error:

     failed: [10.100.140.230] => {"failed": true}
msg: unable to connect, check login credentials (login_user, and login_password, which can be defined in ~/.my.cnf), check that mysql socket exists and mysql server is running

I cannot create this file ~/.my.cnf using template since i am using ansible 1.9.6 and config file in used in higher versions of ansible Can someone please suggest me a workaround for this.

Ansible_Version:

ansible --version
ansible 1.9.6 (stable-1.9 b377301195) last updated 2017/04/09 00:47:37 (GMT -400)
  lib/ansible/modules/core: (detached HEAD 746d51d1ff) last updated 2017/04/09 00:47:59 (GMT -400)
  lib/ansible/modules/extras: (detached HEAD 2c073442b0) last updated 2017/04/09 00:48:19 (GMT -400)
  configured module search path = /opt/ansible/library
1

There are 1 best solutions below

0
elhostis On BEST ANSWER

First, you need to install the python-mysqldb package on the client. Is it ok ?

Then, you don't have setup the host. Is it normal ?

  mysql_db:
    login_host: "127.0.0.1"
    login_user: "xxx"
    login_password: "xxx"
    name: "mydatabase"
    state: import
    target: /tmp/mydump.dump

Eric