Chef ENV settings not working Chef ENV settings not working postgresql postgresql

Chef ENV settings not working


I found that the solution that worked for me was to either in the bootstrap shell script, or as inline shell, to copy the /etc/default/lang.sh to the box prior to any recipes being run. (So should be first thing done in the Vagrant file after box definitions)lang file:

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

From here the database should get setup with the UTF-8 encoding. Hope this helps as I have spent days searching for solutions to this, and came up with the bits and pieces from various discussions, but realized that the problem was timing of when the values are set...


the environment variable doesn't work for chef resources.

According to the postgresql cookbook, you should set the attribute node['postgresql']['initdb_locale'] to setup the locale when initializing a database. For example, use this section under parent section name: serverin your .kitchen.yml:

attributes:  postgresql:    initdb_locale: "en_US.UTF_8"


You can drop and recreate the postgres template database as UTF-8 after the fact. Not a perfect solution, but it does work in your Chef recipe. See: http://www.pebra.net/blog/2013/06/10/when-struggling-with-postgresql-and-utf8-slash-latin/

include_recipe "postgresql::server"include_recipe "database::postgresql"execute "Psql template1 to UTF8" douser "postgres"command <<-SQLecho "UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';DROP DATABASE template1;CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE' LC_CTYPE='en_US.utf8'      LC_COLLATE='en_US.utf8';UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';\\c template1VACUUM FREEZE;" | psql postgres -tSQL# only_if '[ $(echo "select count(*) from pg_database where datname = \'template1\' and datcollate = \'en_US.utf8\'" |psql postgres -t) -eq 0 ]'end