On 5/17/19 10:54 AM, Pierre Ochsenbein wrote:
> Any feedback about my error?
> 

The quotes are missing around vro03 when you execute it with Ansible.

BTW: Ansible 2.8. comes with a postgresql_query module.

Regards
         Racke

> 
> 
> Le jeu. 16 mai 2019 à 16:47, Pierre Ochsenbein <[email protected] 
> <mailto:[email protected]>> a écrit :
> 
>     Hi Guys
> 
>     I want to use a SQL query in PostgreSQL Database with ansible and a 
> varibale which is call db_name.
>     I have the result with my varibale.
>     My problem is I don't know how interpret ' ' command in ansible with my 
> variable
> 
>     My simple query works fine:
> 
>     -bash-4.2$ psql -c "SELECT pg_terminate_backend(pid) FROM 
> pg_stat_activity WHERE datname = 'vro03';"
>     pg_terminate_backend
>     ----------------------
>     t
>     (1 row)
> 
> 
>     Command line in my Playbook:
>       command: 'scl enable rh-postgresql10 "psql -Upostgres 
> --command=\"SELECT pg_terminate_backend(pid) FROM
>     pg_stat_activity WHERE usename = {{ db_name }}\""'
> 
> 
>     Output Error:
> 
>     TASK [../roles/removedb : Kill Session on Database]
>     
> *****************************************************************************************************************************************
>     fatal: [DEMO0249]: FAILED! => {"changed": false, "cmd": ["scl", "enable", 
> "rh-postgresql10", "psql -Upostgres
>     --command=\"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE 
> usename = vro03\""], "delta":
>     "0:00:00.043902", "end": "2019-05-16 16:24:47.597238", "msg": "non-zero 
> return code", "rc": 1, "start": "2019-05-16
>     16:24:47.553336", "stderr": "ERROR:  column \"vro03\" does not 
> exist\nLINE 1: ...ate_backend(pid) FROM
>     pg_stat_activity WHERE usename = vro03\n                                  
>                                 ^",
>     "stderr_lines": ["ERROR:  column \"vro03\" does not exist", "LINE 1: 
> ...ate_backend(pid) FROM pg_stat_activity WHERE
>     usename = vro03", "                                                       
>            ^"], "stdout": "",
>     "stdout_lines": []}
>             to retry, use: --limit 
> @/home/ansible/projects/linuxbootstrap/playbooks/postgresql_removedb.retry
>     PLAY RECAP
>     
> **********************************************************************************************************************************************************************************
> 
>     DEMO0249                   : ok=1    changed=0    unreachable=0    
> failed=1
> 
> 
> 
> -- 
> Cordialement,
> 
> *Pierre Ochsenbein*
> Mobile: +33668295394
> [email protected] <mailto:[email protected]>
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to
> [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CABG8FoN6Jz1FgNgN2aj5GsF0VJHzMCChXz1D_v-sxdAhva92dQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CABG8FoN6Jz1FgNgN2aj5GsF0VJHzMCChXz1D_v-sxdAhva92dQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/aa57cf51-edfe-d8b5-feee-a113e21d2aac%40linuxia.de.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to