3

I'm trying to add database and user in an existing pgsql database (on a centOS 7.1 server). I'm using postgresql_user and postgresql_db modules (Ansible 2.2) to do it but I get the error :

fatal: [XXXXXXXXXXXXXX]: FAILED! => {"changed": false, "failed": true, "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.6543\"?\n"}

I'm using the following task for database creation

- name: Create database
  postgresql_db: name=db port=6543
  become: true
  become_user: postgres

For now, I have done this which is working fine but is not idempotent :

- name: Create database
  command: {{ PGBIN }}/bin/createdb db -p 6543 -w
  become: true
  become_user: postgres

I have installed as required the psycopg2 package. For information the database is not installed in the standard directory and is not using standard port 5432.

2
  • Hello everydody, still no idea ? Commented Nov 28, 2016 at 9:11
  • I also have faced this issue with ansible 2.2 on debian 8 Commented Dec 30, 2016 at 19:27

1 Answer 1

1

Try either of the following:

  • pass the correct path to your postgres socket in via the login_unix_socket parameter
  • Switch to an IP connections and use login_host, login_user, and login_password but you'll need to set the postgres user password or create another superuser.

Here's what one of my tasks looks like

- name: Ensure application database is created
  postgresql_db:  name={{ postgres_app_db }}
                  encoding='UTF-8'
                  lc_collate='en_US.UTF-8'
                  lc_ctype='en_US.UTF-8'
                  state=present
                  login_host={{ postgres_client_host }}
                  login_user="{{ postgres_superuser }}"
                  login_password="{{ postgres_superuser_password }}"
                  port="{{ postgres_client_port }}"

I prefer to use IP connections because in my setup they'll work when run against the DB server or an application server.

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

Comments

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.