postgresql_query postgresql Module help

24 views
Skip to first unread message

Pourab Bhattacharyya

unread,
May 21, 2021, 9:25:19 AM5/21/21
to Ansible Project

Hi,

I'm trying to database query by ansible postgresql_query module. I'm using positional_args parameter for dynamically sending database parameter value.

This my ansible block:

- set_fact:
    joined_ts_list: |-
      {{ user_def_tablespace | join("','") | string}}
  when: inventory_hostname in groups ['edbmaster'] and user_def_tablespace is defined

- name: Check the tablespace details
  postgresql_query:
    db: "{{ edb_databasename }}"
    port: "{{ DB_PORT }}"
    login_unix_socket: /tmp
    login_user: "{{ edb_user }}"
    query: select spcname,pg_tablespace_location(oid) from pg_tablespace where spcname in (%s)
    positional_args:
    - '{{ joined_ts_list }}'
  when: inventory_hostname in groups ['edbmaster'] and user_def_tablespace is defined
  register: pg_query_op

- name: Tablespace status details
  debug:
    msg: "{{ pg_query_op.query }}"
  when: inventory_hostname in groups ['edbmaster'] and user_def_tablespace is defined


Here user_def_tablespace is list variable in my variable file.

user_def_tablespace:
  - data_tbspc
  - index_tbspec

My issue is that the variable names having extra single quotes when I'm passing it as an argument but during the set_fact there is no extra double quote. Like below

TASK [extra_user_def_taks : debug] **************************************************************************************************************************
ok: [10.174.131.31] => {
    "msg": "data_tbspc','index_tbspec" ---> only one single quote
}
TASK [extra_user_def_taks : Tablespace status details] ******************************************************************************************************
ok: [10.174.131.31] => {
    "msg": "select spcname,pg_tablespace_location(oid) from pg_tablespace where spcname in ('data_tbspc'',''index_tbspec')" ---> Extra single quote is appending
}

I'm not able to debug this issue. Hope I'm clear with my problem.
Need your expert advise to resolve this problem.

Thanks,
Pourab

vinoth kumar

unread,
May 22, 2021, 2:54:39 PM5/22/21
to ansible...@googlegroups.com
Hi, 
I haven’t followed all the code . But not sure why do you need double quotes in join

 joined_ts_list: |-
      {{ user_def_tablespace | join(',') | string}}



On Fri 21. May 2021 at 15:25, Pourab Bhattacharyya <pourab...@gmail.com> wrote:

Hi,

I'm trying to database query by ansible postgresql_query module. I'm using positional_args parameter for dynamically sending database parameter value.

This my ansible block:

- set_fact:
   
--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/683a9d3d-1732-44a3-b6ad-2350458355e5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages