6

I tried to create simple dev environment with vagrant but fall in problem with postgres.

My Vagrantfile is simple:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "forwarded_port", guest: 8000, host: 8000
  config.vm.network :public_network

  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
  end
end

and I use ansible for provision:

- name: Configure development machine
  hosts: all
  sudo: True
  tasks:
    - name: install postgres
      apt: name={{ item }} update_cache=yes
      with_items:
        - postgresql 
        - postgresql-contrib

but something goes wrong and postgres installs incorrect

When I ssh to VM and I see strange things:

 $ /etc/init.d/postgresql start
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LC_TIME = "uk_UA.UTF-8",
        LC_MONETARY = "uk_UA.UTF-8",
        LC_ADDRESS = "uk_UA.UTF-8",
        LC_TELEPHONE = "uk_UA.UTF-8",
        LC_NAME = "uk_UA.UTF-8",
        LC_MEASUREMENT = "uk_UA.UTF-8",
        LC_IDENTIFICATION = "uk_UA.UTF-8",
        LC_NUMERIC = "uk_UA.UTF-8",
        LC_PAPER = "uk_UA.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

and there is no /etc/postgresql directory(but /etc/postgresql-common is present) Any thoughts?

Github repo

alefteris
  • 1,126
  • 8
  • 21
kharandziuk
  • 12,020
  • 17
  • 63
  • 121
  • 1
    Can you try `env -i /etc/init.d/postgresql start` to confirm it's locale issue ? – Gea-Suan Lin Dec 05 '14 at 22:06
  • @gslin I have the same issue, just with a different locale, el_GR instead of uk_UA. Here is what you requested: vagrant@vagrant-ubuntu-trusty-64:~$ sudo env -i /etc/init.d/postgresql start * No PostgreSQL clusters exist; see "man pg_createcluster" – alefteris Mar 21 '15 at 10:49
  • I'm not so familar with the setup in Ubuntu, but in RHEL/Centos you have to do 'service postgresql initdb' to create the cluster first. Maybe try `/etc/init.d/postgresql initdb` or failing that `pg_ctl initdb` – harmic Mar 21 '15 at 11:57
  • Worked around it by generating the el_GR.UTF-8 locale with the task: locale_gen: name=el_GR.UTF-8 state=present. Postgres installs and starts ok after that. But what if I do not want to generate the locale? Is there are way to make ansible/vagrant ignore my host laptop locale settings and stick with en_US.UTF-8 in the vm only? – alefteris Mar 21 '15 at 12:04

2 Answers2

7

Add the following lines to shell startup file

LANGUAGE=en_US.UTF-8
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8

And then run (with root privileges)

locale-gen en_US.UTF-8
dpkg-reconfigure locales
Railslide
  • 5,344
  • 2
  • 27
  • 34
  • Can I do the `dpkg-reconfigure locales` step with ansible (does it work non-interactively)? If you could write down the ansible tasks to perform your instructions, it would be even better. Thanks. – alefteris Mar 28 '15 at 10:49
  • I am not super familiar with Ansible, but this module could be perhaps what you need http://docs.ansible.com/locale_gen_module.html (Here the source with a bit more documentation https://github.com/ansible/ansible-modules-extras/blob/400166a655b304094005aace178d0fab1cfe9763/system/locale_gen.py). If that doesn't work you could save those commands as a shell script and running with `- shell: locale_script.sh` – Railslide Mar 28 '15 at 11:18
3

you can solve this issue logging in the ubuntu machine and reconfiguring locales with the following command:

dpkg-reconfigure locales

and choose the locale you want.

After solving locale issue, you probably want to initialize the cluster and structure of postgres using:

/etc/init.d/postgresql start

You should after that, configure it properly. I'm using version 9.3 of postgres, so the path of the configuration is

/etc/postgresql/9.3/main

Cheers

LEslie

UrsoBranco
  • 116
  • 4