ansible-examples icon indicating copy to clipboard operation
ansible-examples copied to clipboard

postgresql.yml un able to connect to server

Open essanpupil opened this issue 10 years ago • 7 comments

hello, when i execute postgressql.yml, i got the following result:

failed: [trustme] => {"failed": true}
msg: unable to connect to database: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

FATAL: all hosts have already failed -- aborting

my ansible version is: 1.9.2 my remote host is: ubuntu server 14.04 32 bit (inside virtual box)

Is there anything wrong, and how do i fix it? thanks

essanpupil avatar Aug 25 '15 10:08 essanpupil

Which example you are talking about?

varnav avatar Aug 25 '15 11:08 varnav

@essanpupil post the full output, may help to figure out the issue.

gregdek avatar Aug 26 '15 14:08 gregdek

Sorry, i'm too busy with my other problems. So here is my complete output:

pupil@DreamRunner:~/ansible_training$ ansible-playbook install_config_postgre.yml -K
SUDO password: 

PLAY [trustme] **************************************************************** 

TASK: [ensure apt cache is up to date] **************************************** 
ok: [trustme]

TASK: [ensure packages are installed] ***************************************** 
ok: [trustme] => (item=postgresql,libpq-dev,python-psycopg2)

PLAY [trustme] **************************************************************** 

TASK: [ensure database is created] ******************************************** 
failed: [trustme] => {"failed": true}
msg: unable to connect to database: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?


FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/pupil/install_config_postgre.retry

trustme                    : ok=2    changed=0    unreachable=0    failed=1 

and here is my .yml file

---
- hosts: trustme
  sudo: yes
  gather_facts: no

  tasks:
  - name: ensure apt cache is up to date
    apt: update_cache=yes
  - name: ensure packages are installed
    apt: name={{item}}
    with_items:
          - postgresql
          - libpq-dev
          - python-psycopg2


- hosts: trustme
  sudo: yes
  sudo_user: postgres
  gather_facts: no

  vars:
    dbname: scam_db
    dbuser: django
    dbpassword: katarahasia

  tasks:
  - name: ensure database is created
    postgresql_db: name={{dbname}}

  - name: ensure user has access to database
    postgresql_user: db={{dbname}} name={{dbuser}} password={{dbpassword}} priv=ALL

  - name: ensure user does not have unnecessary privilege
    postgresql_user: name={{dbuser}} role_attr_flags=NOSUPERUSER,NOCREATEDB

i hope this helps

essanpupil avatar Sep 06 '15 21:09 essanpupil

This happens to me as well, same symptoms, same versions.

jaywink avatar Oct 31 '15 19:10 jaywink

This happens to me too.

lowks avatar May 31 '16 07:05 lowks

To overcome this, I've added these two tasks to my roles which use Ubuntu 14.04, which seems to suffer from this problem.

- name: Locale patch for postgres
  lineinfile: dest=/etc/default/locale line='LANGUAGE="en_US:en"' state=present
- name: Locale patch for postgres
  lineinfile: dest=/etc/default/locale line='LC_ALL="en_US.UTF-8"' state=present

It's not .... ideal, but for my stuff it does the job. If done before installing postgresql via apt, it will install properly. I believe this is the problem described in full.

jaywink avatar Jun 02 '16 16:06 jaywink