1

I have Ansible playbook that is applied to virtual machine. The plyabook is installing Postgresql DB, set up the connection parameters in postgresql.conf and pg_hba.conf. But now I want to create a new user with REPLICATION role using postgresql_user module. But receive an error when doing this:

fatal: [10.0.15.20]: FAILED! => {
    "changed": false,
    "failed": true,
    "invocation": {
        "module_args": {
            "db": "",
            "encrypted": false,
            "expires": null,
            "fail_on_user": true,
            "login_host": "",
            "login_password": "",
            "login_unix_socket": "",
            "login_user": "postgres",
            "name": "replicador",
            "no_password_changes": false,
            "password": null,
            "port": "5432",
            "priv": null,
            "role_attr_flags": "REPLICATION",
            "state": "present",
            "user": "replicador"
        },
        "module_name": "postgresql_user"
    },
    "msg": "unable to connect to database: could not connect to server: No such file or directory\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket \"/var/run/postgresql/.s.PGSQL.5432\"?\n"
}

The only thing that I could found is that I need to use

become: yes
become_user: postgres

However it didn't change anything

Here is my ansible task:

- name: create repication user
  become: yes
  become_user: postgres
  postgresql_user:
    state: present
    name: replicador
    encrypted: no
    role_attr_flags: REPLICATION

And postgresql setting in postgresql.conf

listen_addresses = '*'

And pg_hba.conf

host       all         all        all           trust

1 Answer 1

2

Judging by your error postgres is trying to connect to server via unix socket instead of tcp one. You should either add the following string to pg_hba.conf

local   all             all                                     trust

to trust all unix socket connections or try to specify login_host: 127.0.0.1 to postgresql_user role. That part is actually strange, because as per documentation login_host defaults to localhost.

And also make sure that your database is really running, just in case you missed that part somewhere in your playbook.

Sign up to request clarification or add additional context in comments.

1 Comment

Even though I had the handler that should restart the postgresql, and it was trigged, looks like it wasn't started when I was trying to create the user. I moved it after the postrgesql service starting task and it works. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.