Execut script with Ansible

can you please share what actually error log you are getting.

Hello Varsha,

For exemple if in my script sql “real.sql” there is commande line toto
I have this error :

Traceback (most recent call last):
File “./script_sql_4.py”, line 19, in
cur.execute(f.read().decode(‘utf-8’))
File “/usr/lib/pymodules/python2.7/pymssql.py”, line 196, in execute
raise OperationalError, e[0]
pymssql.OperationalError: SQL Server message 2812, severity 16, state 62, line 1:
Could not find stored procedure ‘toto’.
DB-Lib error message 2812, severity 16:
General SQL Server error: Check messages from the SQL Server

I want get statut of my command “cur.execute(f.read().decode(‘utf-8’))” in python after this command is execute
for after get log message error with this value.

Someone have any idea please ?

Thanks very much Community Ansible !! :slight_smile:

Best Regards,

Hello Varsha,

For exemple if in my script sql "real.sql" there is commande line toto
I have this error :

Traceback (most recent call last):
File "./script_sql_4.py", line 19, in <module>
cur.execute(f.read().decode('utf-8'))
File "/usr/lib/pymodules/python2.7/pymssql.py", line 196, in execute
raise OperationalError, e[0]
pymssql.OperationalError: SQL Server message 2812, severity 16, state 62, line 1:
Could not find stored procedure 'toto'.
DB-Lib error message 2812, severity 16:
General SQL Server error: Check messages from the SQL Server

I want get statut of my command "*cur.execute(f.read().decode('utf-8'))*" in python after this command is execute
for after get log message error with this value.

So you want the error message from your script in your Ansible playbook? How does your task looks like right now?

Regards
        Racke

Hello,

Yes my task is this :

  • name: “Execut script python”
    shell: ./myscript.py
    delegate_to: localhost

I want to get statut of my command line in my script for get message error.

Thanks very much Community Ansible :slight_smile:

Best Regards,

Karther

Hello,

Yes my task is this :

- name: "Execut script python"
shell: ./myscript.py
delegate_to: localhost

I want to get statut of my command line in my script for get message error.

Please try this (untested):

- name: "Execut script python"
  shell: ./myscript.py
  register: myscript
  delegate_to: localhost
  failed_when: false

- debug:
    msg: "{{ myscript[stderr_lines] }}"

The failed_when condition is necessary to reach the debug task.

Regards
        Racke

Hello,

Yes this register variable error works but i want to get status of execution of my python programme cur.execute :
I want to know from this programme python if cur.execute is success execute or not …

#!/usr/bin/python

import pymssql

conn = pymssql.connect(host=“ihospisql02”, user=“sa_ofs”, password=“#Adm!n0fS1”, database=“my_database”)
cur = conn.cursor()

with open(‘real.sql’) as f:
cur.execute(f.read().decode(‘utf-8’))
conn.commit()

cur.close()

Do you understand what i want please Community Ansible ?

Thanks very much

Best Regards,

Karther

Hello,

Yes this register variable error works but i want to get status of execution of my python programme *cur.execute* :
I want to know from this programme python if *cur.execute* is success execute or not ...

That's up to your script, really. In case *cur.execute* fails it should print the error to STDERR and exit
with exit code != 0.

Regards
         Racke