# Can't add new postgresql\_hba records using postgresql\_hba module

**URL:** <https://forum.ansible.com/t/cant-add-new-postgresql-hba-records-using-postgresql-hba-module/32966>\
**Category:** Ansible Project\
**Created:** [May 19, 2020, 10:44am UTC](https://forum.ansible.com/t/cant-add-new-postgresql-hba-records-using-postgresql-hba-module/32966 "2020-05-19T10:44:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ikhsan\_Faruqi](https://avatars.discourse-cdn.com/v4/letter/i/a6a055/32.png) [@Ikhsan\_Faruqi](https://forum.ansible.com/u/Ikhsan_Faruqi)\
**Post date:** [May 19, 2020, 10:44am UTC](https://forum.ansible.com/t/cant-add-new-postgresql-hba-records-using-postgresql-hba-module/32966/1 "2020-05-19T10:44:36Z")

</div>

Hi, I trying to add new hba\_records using [pg\_hba\_module](https://docs.ansible.com/ansible/latest/modules/postgresql_pg_hba_module.html) but got this error:

`  
failed: [pg-12] (item={‘hba\_database’: ‘test-db’, ‘hba\_users’: ‘johndoe’, ‘hba\_connection\_type’: ‘host’, ‘hba\_source’: ‘0.0.0.0/0’, ‘hba\_method’: ‘trust’}) =\> {“ansible\_loop\_var”: “item”, “changed”: false, “item”: {“hba\_connection\_type”: “host”, “hba\_database”: “test-db”, “hba\_method”: “trust”, “hba\_source”: “0.0.0.0/0”, “hba\_users”: “johndoe”}, “msg”: "value of method must be one of: trust, reject, md5, password, gss, sspi, krb5, ident, peer, ldap, radius, cert, pam, scram-sha-256, got: trust "}

`

this is what my vars.yml looks like:

`

- hba\_records:
- hba\_database: test-db  
hba\_users: johndoe  
hba\_connection\_type: host  
hba\_source: 0.0.0.0/0  
hba\_method: trust
- hba\_database: test-db  
hba\_users: alexsong  
hba\_connection\_type: host  
hba\_source: 0.0.0.0/0  
hba\_method: trust  
`

my ansible info:

`

➜ ~ ansible --version  
ansible 2.9.5  
config file = None  
configured module search path = [‘/Users/MASKED/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]  
ansible python module location = /Users/MASKEd/Library/Python/3.7/lib/python/site-packages/ansible  
executable location = /Users/MASKED/Library/Python/3.7/bin/ansible  
python version = 3.7.5 (default, Nov 1 2019, 02:16:23) [Clang 11.0.0 (clang-1100.0.33.8)]

`

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 19, 2020, 10:49am UTC](https://forum.ansible.com/t/cant-add-new-postgresql-hba-records-using-postgresql-hba-module/32966/2 "2020-05-19T10:49:07Z")

</div>

> Hi, I trying to add new hba\_records using pg\_hba\_module  
> \<[https://docs.ansible.com/ansible/latest/modules/postgresql\_pg\_hba\_module.html&gt](https://docs.ansible.com/ansible/latest/modules/postgresql_pg_hba_module.html&gt); but got this error:
> 
> \>  
> failed:[pg-12](item={'hba\_database':'test-db','hba\_users':'johndoe','hba\_connection\_type':'host','hba\_source':'0.0.0.0/0','hba\_method':'trust'})=\>{"ansible\_loop\_var":"item","changed":false,"item":{"hba\_connection\_type":"host","hba\_database":"test-db","hba\_method":"trust","hba\_source":"0.0.0.0/0","hba\_users":"johndoe"},"msg":"value  
> of method must be one of: trust, reject, md5, password, gss, sspi, krb5, ident, peer, ldap, radius, cert, pam,  
> scram-sha-256, got: trust "}
> 
> \>
> 
> this is what my vars.yml looks like:
> 
> \>  
> -hba\_records:  
> -hba\_database:test-db  
> hba\_users:johndoe  
> hba\_connection\_type:host  
> hba\_source:0.0.0.0/0  
> hba\_method:trust  
> -hba\_database:test-db  
> hba\_users:alexsong  
> hba\_connection\_type:host  
> hba\_source:0.0.0.0/0  
> hba\_method:trust  
> \>
> 
> my ansible info:

Hello Ikshan,

the module expects the parameters without the hba\_ prefix as clearly stated in the documentation and shown in the examples.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Ikhsan\_Faruqi](https://avatars.discourse-cdn.com/v4/letter/i/a6a055/32.png) [@Ikhsan\_Faruqi](https://forum.ansible.com/u/Ikhsan_Faruqi)\
**Post date:** [May 19, 2020, 11:08am UTC](https://forum.ansible.com/t/cant-add-new-postgresql-hba-records-using-postgresql-hba-module/32966/3 "2020-05-19T11:08:08Z")

</div>

Hi stefan, sorry I forgot to put my playbook, here what it looks like

`

- name: PostgreSQL | Add new HBA records.  
become: yes  
postgresql\_pg\_hba:  
dest: “{{ postgresql\_hba\_file\_path }}”  
contype: “{{ item.hba\_connection\_type }}”  
users: “{{ item.hba\_users }}”  
source: “{{ item.hba\_source }}”  
databases: “{{ item.hba\_database | default(omit) }}”  
method: "{{ item.hba\_method }} "  
notify: restart postgresql  
loop: “{{ hba\_records }}”  
when: setup\_hba == true

`

so basically I want to add multiple records, so I create some loops.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 19, 2020, 11:13am UTC](https://forum.ansible.com/t/cant-add-new-postgresql-hba-records-using-postgresql-hba-module/32966/4 "2020-05-19T11:13:49Z")

</div>

> Hi stefan, sorry I forgot to put my playbook, here what it looks like
> 
> \>  
> - name: PostgreSQL | Add new HBA records.  
> become: yes  
> postgresql\_pg\_hba:  
> dest: "{{ postgresql\_hba\_file\_path }}"  
> contype: "{{ item.hba\_connection\_type }}"  
> users: "{{ item.hba\_users }}"  
> source: "{{ item.hba\_source }}"  
> databases: "{{ item.hba\_database | default(omit) }}"  
> method: "{{ item.hba\_method }} "  
> notify: restart postgresql  
> loop: "{{ hba\_records }}"  
> when: setup\_hba == true  
> \>

Maybe the trailing space in

&nbsp;&nbsp;&nbsp;method: "{{ item.hba\_method }} "

causes the problem ?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Ikhsan\_Faruqi](https://avatars.discourse-cdn.com/v4/letter/i/a6a055/32.png) [@Ikhsan\_Faruqi](https://forum.ansible.com/u/Ikhsan_Faruqi)\
**Post date:** [May 19, 2020, 11:16am UTC](https://forum.ansible.com/t/cant-add-new-postgresql-hba-records-using-postgresql-hba-module/32966/5 "2020-05-19T11:16:15Z")

</div>

No, it is not the problem, I tried removing whitespace, and it still errors.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 19, 2020, 12:12pm UTC](https://forum.ansible.com/t/cant-add-new-postgresql-hba-records-using-postgresql-hba-module/32966/6 "2020-05-19T12:12:38Z")

</div>

Is that the same error?

Because @Stefan Hornburg (Racke) is right, if you look closely at the  
FIRST error:

"msg": "value of method must be one of: trust, reject, md5, password,  
gss, sspi, krb5, ident, peer, ldap, radius, cert, pam, scram-sha-256,  
got: trust "}

You can see that it has an extra space at the end.

If you say you have fixed that, then whatever error is left must be different.

Did you forget to post the new error?

---

<div class="post-metadata">

**Author:** ![Ikhsan\_Faruqi](https://avatars.discourse-cdn.com/v4/letter/i/a6a055/32.png) [@Ikhsan\_Faruqi](https://forum.ansible.com/u/Ikhsan_Faruqi)\
**Post date:** [May 19, 2020, 2:54pm UTC](https://forum.ansible.com/t/cant-add-new-postgresql-hba-records-using-postgresql-hba-module/32966/7 "2020-05-19T14:54:01Z")

</div>

I solve the problem by change double quote to single quote in the task that render item from loop.
