PostgreSQL failing peer authentication with Ansible PostgreSQL failing peer authentication with Ansible postgresql postgresql

PostgreSQL failing peer authentication with Ansible


This worked for me:

- name: Create postgres database  become: true  become_user: postgres  postgresql_db:    name: <database-name>

In your specific case the user might be pgsql, but I think usually the user is postgres.


Or with slightly different syntax (from Ansible 1.9) and for user creation (might be helpful for someone)

- name: Create postgres user  postgresql_user: name={{ pg_user }} password={{ pg_password }}  become: true  become_user: postgres


For those running into "Failed to set permissions on the temporary files Ansible needs to create..." in order to switch to the postgres user with become_user you can leverage pipelining on Ubuntu hosts.

Create a ansible.cfg in your playbook directory and add the following lines:

[ssh_connection]pipelining=True

Update: according to @lolcode Ansible 2.9.0 has updated to ansible_pipelining

   [ssh_connection]   ansible_pipelining = true

Update 4/30/2020: for those who still have issues, try installing acl which will cause Ansible to use this acl filesystem to mount module that need to be accessible by the 2nd user instead of making them readable by everyone. Thanks @Andreas Florath

- name: install setfacl support  become: yes  apt: pkg=acl