Unable to Install PostgreSQL using Ansible

Hello Everyone,

I’m new to Ansible, and I ended up having a problem with my playbook to install psql. I already tried everything and searched everywhere.

When I perform the following task:

  • name: Ensure database is created
    become_user: postgres
    become: true
    postgresql_db: name={{ db_name }}
    encoding=‘UTF-8’
    lc_collate=‘en_US.UTF-8’
    lc_ctype=‘en_US.UTF-8’
    template=‘template0’
    state=present

I keep getting erros like:

fatal: [X.X.X.X]: FAILED! => {
“changed”: false,
“failed”: true,
“invocation”: {
“module_name”: “postgresql_db”
},
“module_stderr”: “OpenSSH_6.9p1, LibreSSL 2.1.8\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 82852\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to X.X.X.X closed.\r\n”,
“module_stdout”: “sudo: a password is required\r\n”,
“msg”: “MODULE FAILURE”
}

If needed I can post more code. I’m almost giving up and install this by hand.

Thank you!

Hello Everyone,

....
....

  become_user: postgres
  become: true

...
...

    "module_stdout": "sudo: a password is required\r\n",
    "msg": "MODULE FAILURE"

Ansible needs a password so it can sudo to the postgres user.

As the error message says, you need to provide the sudo password, add "ask_pass = True" og --become/-b on the commandline.