postgresql_query postgresql Module help

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

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}}