How use mssql-cli on Debian

12 views
Skip to first unread message

Ryad karkar

unread,
Jun 6, 2019, 6:07:34 AM6/6/19
to Ansible Project
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 !! ;)

Thanks,

Regards,

Dick Visser

unread,
Jun 6, 2019, 7:04:56 AM6/6/19
to ansible...@googlegroups.com
On Thu, 6 Jun 2019 at 12:07, Ryad karkar <ryad9...@gmail.com> wrote:
>
> 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 ?

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.




--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Ryad karkar

unread,
Jun 6, 2019, 7:21:27 AM6/6/19
to Ansible Project
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 !! ;)

Regards,

Wawrzek Niewodniczanski

unread,
Jun 6, 2019, 11:13:28 AM6/6/19
to ansible...@googlegroups.com
On Thu, 6 Jun 2019 at 11:07, Ryad karkar <ryad9...@gmail.com> wrote:
>
> Hi all,
>
> I have install mssql-cli for execut command line on instance MSSQL but when i use this task:
>
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

--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: jo...@wawrzek.name
Linux User #177124
Reply all
Reply to author
Forward
0 new messages