# postgresql\_query postgresql Module help

**URL:** <https://forum.ansible.com/t/postgresql-query-postgresql-module-help/35208>\
**Category:** Ansible Project\
**Created:** [May 21, 2021, 1:25pm UTC](https://forum.ansible.com/t/postgresql-query-postgresql-module-help/35208 "2021-05-21T13:25:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pourab\_Bhattacharyya](https://avatars.discourse-cdn.com/v4/letter/p/848f3c/32.png) [@Pourab\_Bhattacharyya](https://forum.ansible.com/u/Pourab_Bhattacharyya)\
**Post date:** [May 21, 2021, 1:25pm UTC](https://forum.ansible.com/t/postgresql-query-postgresql-module-help/35208/1 "2021-05-21T13:25:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vinod93pop](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@vinod93pop](https://forum.ansible.com/u/vinod93pop)\
**Post date:** [May 22, 2021, 6:54pm UTC](https://forum.ansible.com/t/postgresql-query-postgresql-module-help/35208/2 "2021-05-22T18:54:12Z")

</div>

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