Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
saschagottfried opened this issue Sep 23, 2015 · 4 comments

Comments

@saschagottfried
Copy link

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

@saschagottfried saschagottfried changed the title Ch06 - task 'create a postgres user' fails if control machine have additional locales Ch06 - task 'create a postgres user' fails if control machine has additional locales Sep 23, 2015
@shiiaii
Copy link

shiiaii commented Aug 12, 2016

I met the similar issue as yours.
In my enviroment, the default installed items as below zh_CN.UTF-8 is missing
$ sudo locale -a
C
C.UTF-8
en_US.utf8
POSIX

vagrant@vagrant-ubuntu-trusty-64:~/mezzanine-example$ sudo locale
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=

then add zh_CN.UTF-8 by command "sudo locale-gen zh_CN.UTF-8"

Then the postgresql can startup .

@saschagottfried
Copy link
Author

saschagottfried commented Aug 15, 2016

Thanks for your suggestion. I was generating additional locales on the remote machine as well. But this issue is about fixing vagrant and/or vagrant playbook so that (manually) modifying the remote machine is not necessary anymore.

@shiiaii
Copy link

shiiaii commented Aug 17, 2016

I do this by adding an ugly specfic task, but this could be diff from all other enviroments

  • name: locale bug for postgresql
    command: locale-gen zh_CN.UTF-8
    become: True

@saschagottfried
Copy link
Author

This sounds good to me. Sorry, I did not get it in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants