---
- name: PgBouncer is installed
  ansible.builtin.apt:
    name: pgbouncer
    state: present

- name: Limit for PgBouncer is set
  ansible.builtin.lineinfile:
    path: /etc/default/pgbouncer
    regexp: "ulimit -n"
    line: ulimit -n 65536
  notify: restart pgbouncer

- name: Add config file for PgBouncer
  ansible.builtin.template:
    src: pgbouncer.ini.j2
    dest: /etc/pgbouncer/pgbouncer.ini
  notify: restart pgbouncer
  
- name: Populate userlist.txt
  ansible.builtin.template:
    src: userlist.txt.j2
    dest: /etc/pgbouncer/userlist.txt
  notify: restart pgbouncer
