0

On a RHEL 7.2 server I've set up environment variables in /etc/environment similar to this:

DB_LOGIN='DOMAIN\username'
DB_PASSWORD='password'

The file was then referenced as an EnvironmentFile in /etc/systemd/system/httpd.service.d/override.conf. After rebooting the server I can see that the env. var. is set properly (by running the env command). In my Rails environment, I have the following in my database.yml file based on what I learned from Failing to access environment variables within `database.yml` file:

    default: &default
      adapter: sqlserver
      ...
      username: <%= ENV['DB_LOGIN'] %>
      password: <%= ENV['DB_PASSWORD'] %>

This setup works fine when executing my rake tasks. Also of note, when I run erb against the database.yml, it looks correct (the backslash is present). However in my Apache/Passenger configuration (httpd-2.4.6-40.el7_2.4.x86_64 and Phusion Passenger 5.1.7), the username loses the backslash (the value is DOMAINusername).

I've changed the env var to have two backslashes (DOMAIN\\username) and then it works fine in the Apache/Passenger config, but my rake tasks fail due to the double backslash in the username.

Is there a way to have an environment variable value that contains a backslash work in both of these situations?

I'm not really looking to use a gem/plugin like Figaro or dotenv.

Thanks for any guidance!

MRudowsky
  • 1
  • 2
  • Look at the answer here, escaping the backslash might work for you. (https://stackoverflow.com/questions/31328386/ruby-on-rails-4-on-heroku-environment-variables-with-backslash-escape) – kparekh01 Mar 15 '18 at 20:31
  • Thanks, but tried it. Did not work. The value is still missing the backslash. Almost like the backslash gets lost before the env var is evaluated in database.yml. – MRudowsky Mar 16 '18 at 19:45

0 Answers0