How use mssql-cli on Debian

Hi all,

I have install mssql-cli for execut command line on instance MSSQL but when i use this task:

  • name: “conenct instance mssql”
    command: mssql-cli -S my_hote -U my_user
    delegate_to: localhost

This task not works but on my prompt Debian this command line works why ?

Someone can help me please !! :wink:

Thanks,

Regards,

I'm not familair with mssql-cli but from the docs at
https://github.com/dbcli/mssql-cli/blob/master/doc/usage_guide.md it
appears to be an "interactive command line query tool".
You ansible task just runs one command, which connects to a database.
That's not very useful.
So, what are you trying to do? Do a query and return results?

It might be that mssql-cli can ONLY operate in interactive mode which
makes it unsuitable for this purpose.

Hi Dick Visser,

I understand, i will think that with mssqli-cli on Ansible, i will can execut script sql or execut command sql with module command or shell of Ansible.

it’s very bad that there are not intereaction with some tool like mssql-cli and Ansible …

Thank you for you help Dick Visser !! :wink:

Regards,

Have you try to use sqlcmd?
https://docs.microsoft.com/en-us/sql/ssms/scripting/sqlcmd-use-the-utility?view=sql-server-2017

We have following test in one of our roles:

    - name: Check if the SQL users can login to their databases
      shell: |
        set -eu
        sqlscript='SELECT * FROM DATABASECHANGELOG;'
        /opt/mssql-tools/bin/sqlcmd \
          -S {{ sqlserver | quote }} \
          -U {{ sqluser | quote }} \
          -P {{ sqlpass | quote }} \
          -d {{ database | quote }} \
          -Q "${sqlscript}"
      loop: '{{ test_databases }}'
      vars:
        sqlserver: '{{ init_mssql_db_sql_server }}'
        sqluser: '{{ item.username | default(item.database) }}'
        sqlpass: '{{ item.password }}'
        database: '{{ item.database }}'

Wawrzek