Skip to content

Ch06 - task 'create a postgres user' fails if control machine has additional locales  #6

@saschagottfried

Description

@saschagottfried

Working through chapter 6 running ansible-playbook mezzanine.yml fails at this point

$ ansible-playbook mezzanine.yml 

PLAY [Deploy mezzanine] ******************************************************* 

GATHERING FACTS *************************************************************** 
ok: [web]

...

TASK: [create a user] ********************************************************* 
failed: [web] => {"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

debugging Vagrant host

vagrant@vagrant-ubuntu-trusty-64:~/mezzanine-example$ psql
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_PAPER = "de_DE.UTF-8",
    LC_ADDRESS = "de_DE.UTF-8",
    LC_MONETARY = "de_DE.UTF-8",
    LC_NUMERIC = "de_DE.UTF-8",
    LC_TELEPHONE = "de_DE.UTF-8",
    LC_IDENTIFICATION = "de_DE.UTF-8",
    LC_MEASUREMENT = "de_DE.UTF-8",
    LC_TIME = "de_DE.UTF-8",
    LC_NAME = "de_DE.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
psql: 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"?

locales of my control machine

$ locale
LANG=en_GB.UTF-8
LANGUAGE=en_GB:en
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=

Validating a running postgres service

vagrant@vagrant-ubuntu-trusty-64:~$ sudo service postgresql start
 * No PostgreSQL clusters exist; see "man pg_createcluster"

Adding missing locales to remote machine

vagrant@vagrant-ubuntu-trusty-64:~$ sudo locale-gen de_DE.utf8
Generating locales...
  de_DE.UTF-8... done
Generation complete.
vagrant@vagrant-ubuntu-trusty-64:~$ sudo locale-gen en_GB.UTF-8
Generating locales...
  en_GB.UTF-8... done
Generation complete.

Following the advice from AskUbuntu

vagrant@vagrant-ubuntu-trusty-64:~$ sudo pg_createcluster 9.3 main --start
Creating new cluster 9.3/main ...
  config /etc/postgresql/9.3/main
  data   /var/lib/postgresql/9.3/main
  locale en_US.UTF-8
  port   5432
vagrant@vagrant-ubuntu-trusty-64:~$ sudo -iu postgres
postgres@vagrant-ubuntu-trusty-64:~$ psql
psql (9.3.9)
Type "help" for help.

postgres=# 

Now Ansible tasks for Postgres succeed

TASK: [create a user] ********************************************************* 
changed: [web]

TASK: [create the database] *************************************************** 
changed: [web]

Just noticed I even added option module_lang to ansible.cfg

hostfile = hosts
remote_user = vagrant
private_key_file = .vagrant/machines/default/virtualbox/private_key
host_key_checking = False
module_lang = en_US.utf8

[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes

The problem itself is well known to people used to work with Postgresql and/or Ansible/Vagrant. To me it is not clear how to fix the playbook and how my machine locales affect the problem. I hope the book author can resolve this. BTW - it is an awesome book.

Environment

Vagrant - Ubuntu/Trusty64

$ vagrant box update
==> default: Checking for updates to 'ubuntu/trusty64'
    default: Latest installed version: 20150911.0.0
    default: Version constraints: 
    default: Provider: virtualbox
==> default: Updating 'ubuntu/trusty64' with provider 'virtualbox' from version
==> default: '20150911.0.0' to '20150916.0.0'...
==> default: Loading metadata for box 'https://atlas.hashicorp.com/ubuntu/trusty64'
==> default: Adding box 'ubuntu/trusty64' (v20150916.0.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20150916.0.0/providers/virtualbox.box
==> default: Successfully added box 'ubuntu/trusty64' (v20150916.0.0) for 'virtualbox'!

Ansible

$ ansible --version
ansible 1.9.3

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions