# Change pg\_hba.conf & postgresql.conf

**URL:** <https://forum.ansible.com/t/change-pg-hba-conf-postgresql-conf/37038>\
**Category:** Ansible Project\
**Created:** [August 26, 2022, 12:44pm UTC](https://forum.ansible.com/t/change-pg-hba-conf-postgresql-conf/37038 "2022-08-26T12:44:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sagan](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Sagan](https://forum.ansible.com/u/Sagan)\
**Post date:** [August 26, 2022, 12:44pm UTC](https://forum.ansible.com/t/change-pg-hba-conf-postgresql-conf/37038/1 "2022-08-26T12:44:27Z")

</div>

Hello,

I’m trying to automatize the editing of these files. I have made a playbook to install PostgreSQL in a controlled node. However, I need to change these 2 files to accept remote connections so I can access the PostgreSQL databases with my PGadmin4.

However, I can’t seem to find how to change the configuration on these files. Is there a module for this? It seems weird that no module can do it. So I’m sure I’ve missed something.

Any advice would be greatly welcomed!

---

<div class="post-metadata">

**Author:** ![ajay\_garad](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@ajay\_garad](https://forum.ansible.com/u/ajay_garad)\
**Post date:** [August 26, 2022, 3:02pm UTC](https://forum.ansible.com/t/change-pg-hba-conf-postgresql-conf/37038/2 "2022-08-26T15:02:45Z")

</div>

Hello ,

I also checked below code

- name: Replace postgresql configuration file to allow remote connection

ansible.builtin.lineinfile:  
path: “{{ postgresql\_conf\_file }}”  
line: ‘{{ item }}’  
owner: postgres  
group: postgres  
mode: ‘0644’  
with\_items:

- “listen\_addresses = ‘\*’”

- “port = 5432”  
become: yes  
become\_user: root

- name: “Allow md5 connection for the db user”  
postgresql\_pg\_hba:  
dest: “{{ pg\_hba\_file}}”  
contype: host  
databases: all  
source: “[0.0.0.0/0](http://0.0.0.0/0)”  
method: md5  
users: “all”  
create: true  
become: yes  
become\_user: root

I hope it will help you…!

Regards,  
Ajay
