1

I'm working on a Rails project which uses PostgreSQL and I want to store the database login details in a file and access them with environment variables using rbenv-vars. I'm running Ubuntu 16.10.

Considering the following files:

pg_hba.conf

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost
  pool: 5
  username: consul
  password: <% ENV['CONSUL_DATABASE_PASSWORD'] %>

.rbenv-vars

SECRET_KEY_BASE=(secret key)
CONSUL_DATABASE_PASSWORD=(database password)

When I try to create the database for the project using the rake db:create command I get this error:

fe_sendauth: no password supplied

I tried storing the password in cleartext and it works, but as you can imagine, I don't want to do that.

helloworld2013
  • 83
  • 1
  • 1
  • 7

3 Answers3

0

fe_sendauth: no password supplied

<% ENV['CONSUL_DATABASE_PASSWORD'] %>

should be

<%= ENV['CONSUL_DATABASE_PASSWORD'] %>
Pavan
  • 32,201
  • 7
  • 42
  • 69
0

Change the line to

password: <%= ENV['CONSUL_DATABASE_PASSWORD'] %>

<% %> just evaluate the content whereas

<%= %> evaluates and insert the content in the place of the tag

Refer this answer for more details on erb tags What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

Deepak Mahakale
  • 19,422
  • 8
  • 58
  • 75
0

In my case, the problem was my having dashes rather than underscores in my environment variable name, i.e.:

<%= ENV['APP-NAME_DATABASE_PASSWORD'] %>

Changing the variable name in config/database.yml to APP_NAME_DATABASE_PASSWORD fixed it for me.

Niek
  • 1,127
  • 11
  • 22