Change pg_hba.conf & postgresql.conf

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!

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
    method: md5
    users: “all”
    create: true
    become: yes
    become_user: root

I hope it will help you…!

Regards,
Ajay