--- - name: Install Postgres apk: name: postgresql update_cache: yes - name: Install Runit service directory file: state: directory path: /etc/sv/postgres mode: '0755' - name: Install Runit service command template: src: run.j2 dest: /etc/sv/postgres/run mode: '755' - name: Install supervise symlink file: state: link force: yes src: /run/supervise.postgres dest: /etc/sv/postgres/supervise follow: false - name: Enable postgres service file: state: link force: yes src: /etc/sv/postgres dest: /var/service/postgres follow: false - name: Write pgpass for 'root' copy: content: | # hostname:port:database:username:password *:*:*:postgres:{{postgres_passwd | replace('\n', '')}} dest: '/root/.pgpass' mode: '0600' when: postgres_passwd is defined - name: Check if Netdata is installed stat: path: /opt/netdata register: nd - name: Write postgres configuration for Netdata copy: content: | --- socket: name: 'local' user: 'postgres' database: 'postgres' {% if postgres_passwd is defined %}password: {{postgres_passwd}}{% endif %} mode: '0600' dest: /opt/netdata/etc/netdata/python.d/postgres.conf owner: 'netdata' when: nd is defined and nd.stat.exists - name: Install the required python modules apk: name: py3-psycopg2 state: present when: nd is defined and nd.stat.exists