# Ansible playbook for creating mysql user not working

**URL:** <https://forum.ansible.com/t/ansible-playbook-for-creating-mysql-user-not-working/28896>\
**Category:** Ansible Project\
**Created:** [October 30, 2018, 6:09am UTC](https://forum.ansible.com/t/ansible-playbook-for-creating-mysql-user-not-working/28896 "2018-10-30T06:09:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arjun\_Ani](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@Arjun\_Ani](https://forum.ansible.com/u/Arjun_Ani)\
**Post date:** [October 30, 2018, 6:09am UTC](https://forum.ansible.com/t/ansible-playbook-for-creating-mysql-user-not-working/28896/1 "2018-10-30T06:09:54Z")

</div>

When running mysql\_user module in ansible it is showing the below error.

**ansible** version - 2.6

**mysql** version - 5.6

**yaml syntax** :-

```auto
- name: Test | mysql
  mysql_user: name=test password=test host=localhost state=present

```

error :-

```auto

fatal: [94.130.87.130]: FAILED! => {
    "changed": false, 
    "module_stderr": "Shared connection to 94.130.87.130 closed.\r\n", 
    "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_73s74m/ansible_module_mysql_user.py\", line 206, in <module>\r\n from ansible.module_utils.basic import AnsibleModule\r\nzlib.error: Error -2 while preparing to decompress data: inconsistent stream state\r\n", 
    "msg": "MODULE FAILURE", 
    "rc": 1
}

```

---

<div class="post-metadata">

**Author:** ![Andrew\_Cockerill](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@Andrew\_Cockerill](https://forum.ansible.com/u/Andrew_Cockerill)\
**Post date:** [October 30, 2018, 8:56am UTC](https://forum.ansible.com/t/ansible-playbook-for-creating-mysql-user-not-working/28896/2 "2018-10-30T08:56:40Z")

</div>

That looks like an issue with the ssh connection. Can you try a couple of things:

1. Verify that you can connect using ssh

2. If you can, try a simple Ansible play like ‘ping’ and see if that works.

---

<div class="post-metadata">

**Author:** ![Arjun\_Ani](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@Arjun\_Ani](https://forum.ansible.com/u/Arjun_Ani)\
**Post date:** [October 30, 2018, 9:03am UTC](https://forum.ansible.com/t/ansible-playbook-for-creating-mysql-user-not-working/28896/3 "2018-10-30T09:03:45Z")

</div>

Andrew,

Thank You for your reply.The issue is not with the ssh connection.The above is only a portion of task that I am running.I was able to execute other tasks successfully.Still not sure why I am not able to get the required output.

---

<div class="post-metadata">

**Author:** ![Andrew\_Cockerill](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@Andrew\_Cockerill](https://forum.ansible.com/u/Andrew_Cockerill)\
**Post date:** [October 30, 2018, 9:22am UTC](https://forum.ansible.com/t/ansible-playbook-for-creating-mysql-user-not-working/28896/4 "2018-10-30T09:22:53Z")

</div>

I’m not familiar with that module, but do you have all the prereqs installed?

---

<div class="post-metadata">

**Author:** ![Andrew\_Cockerill](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@Andrew\_Cockerill](https://forum.ansible.com/u/Andrew_Cockerill)\
**Post date:** [October 30, 2018, 9:54am UTC](https://forum.ansible.com/t/ansible-playbook-for-creating-mysql-user-not-working/28896/5 "2018-10-30T09:54:01Z")

</div>

The Ansible docs say:

- Both `login_password` and `login_user` are required when you are passing credentials. If none are present, the module will attempt to read the credentials from `~/.my.cnf`, and finally fall back to using the MySQL default login of ‘root’ with no password.

---

<div class="post-metadata">

**Author:** ![Arjun\_Ani](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@Arjun\_Ani](https://forum.ansible.com/u/Arjun_Ani)\
**Post date:** [October 30, 2018, 9:57am UTC](https://forum.ansible.com/t/ansible-playbook-for-creating-mysql-user-not-working/28896/6 "2018-10-30T09:57:03Z")

</div>

MySQL server is having the user root with no password.
