# TASK \[Check DB connection\] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* fatal: \[localhost\]: FAILED! =\> {"changed": false, "msg": "unable to connect, chec

**URL:** <https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183>\
**Category:** Ansible Project\
**Created:** [July 3, 2023, 8:07pm UTC](https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183 "2023-07-03T20:07:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [July 3, 2023, 8:07pm UTC](https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183/1 "2023-07-03T20:07:45Z")

</div>

Any idea about this error, the username and password are correct those are dbo creds. I am able to connect through ssms with the same creds but not working through ansible  
also I don’t see @sysconfdir@/freetds.conf / ${HOME}/.freetds.conf" on my linux node…

TASK [Check DB connection] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost]: FAILED! =\> {“changed”: false, “msg”: “unable to connect, check login\_user and login\_password are correct, or alternatively check your @sysconfdir@/freetds.conf / ${HOME}/.freetds.conf”}

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [July 3, 2023, 8:17pm UTC](https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183/2 "2023-07-03T20:17:56Z")

</div>

Hi Narmada,

Could you please provide more context like playbooks used, collections used, modules used, ultimate aim to achieve etc? Without this information, it is really difficult to debug.

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [July 3, 2023, 8:56pm UTC](https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183/3 "2023-07-03T20:56:09Z")

</div>

pymssql-2.2.7

I am just trying to make a sql connection by checking the connectivity to sql server, if this is successfully I have to get some select and update statements working  
this is my playbook—

- name: Execute sql commands  
hosts: localhost  
gather\_facts: false  
become: true  
user: root  
vars\_files:
- group\_vars/mssqlpass.yml  
tasks:
- name: Check DB connection  
community.general.mssql\_script:  
login\_user: “{{ mssql\_login\_user }}”  
login\_password: “{{ mssql\_login\_password }}”  
login\_host: “{{ mssql\_server }}”  
login\_port: “{{ mssql\_port }}”  
db: dbname  
script: “SELECT \*”

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [July 5, 2023, 4:30pm UTC](https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183/4 "2023-07-05T16:30:23Z")

</div>

any other details needed?

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [July 6, 2023, 6:40pm UTC](https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183/5 "2023-07-06T18:40:27Z")

</div>

can some one shower some light here

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [July 6, 2023, 7:10pm UTC](https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183/6 "2023-07-06T19:10:37Z")

</div>

Hi Narmada,

Seems like you have an exception in the mssql\_script module. Can you please try this Python script [https://gist.github.com/Akasurde/b848017c027c71e6e5fd80d5f0f01a8b](https://gist.github.com/Akasurde/b848017c027c71e6e5fd80d5f0f01a8b) since module is swallowing the exception?

---

<div class="post-metadata">

**Author:** ![Will\_McDonald](https://avatars.discourse-cdn.com/v4/letter/w/f475e1/32.png) [@Will\_McDonald](https://forum.ansible.com/u/Will_McDonald)\
**Post date:** [July 6, 2023, 7:12pm UTC](https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183/7 "2023-07-06T19:12:12Z")

</div>

Is {{ mssql\_server }} pointing at:

1. your local machine localhost running SQL Server on Linux directly

2. or a remote machine running SQL Server on Linux

3. or a remote machine running SQL Server on Windows?

If your scenario is #2, have you installed pymssql on the target machine as well as your Ansible control node? (See: [https://docs.ansible.com/ansible/latest/collections/community/general/mssql\_script\_module.html#notes](https://docs.ansible.com/ansible/latest/collections/community/general/mssql_script_module.html#notes))

If your scenarios is #3, see: [https://github.com/ansible/ansible/issues/39612#issuecomment-597451375](https://github.com/ansible/ansible/issues/39612#issuecomment-597451375) (This is a different Ansible module but it’s using the same Python under the covers.)

You might get more help if you can provide proper output (with passwords redacted) of an actual run with -v[vv], the inventory and as much more information as you possibly can.

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [July 26, 2023, 5:03pm UTC](https://forum.ansible.com/t/task-check-db-connection-fatal-localhost-failed-changed-false-msg-unable-to-connect-chec/38183/8 "2023-07-26T17:03:54Z")

</div>

Thank you so much, I am able to fix the issue… If your scenarios is #3, see: [https://github.com/ansible/ansible/issues/39612#issuecomment-597451375](https://github.com/ansible/ansible/issues/39612#issuecomment-597451375) (This is a different Ansible module but it’s using the same Python under the covers.) this helped me
