Forum: Ruby on Rails Using Chef to set the database name, username, and password

99713a5ec23b5195250c9910eb13f01f?d=identicon&s=25 Jason Hsu, Rubyist (Guest)
on 2013-11-01 18:59
(Received via mailing list)
One of my Ruby on Rails apps is Bargain Stock Funds
(, and it relies on a Ruby gem called
bsf_scrape ( to obtain and
data on stock funds and then save the results in a PostgreSQL database.

As you well know, the config/database.yml file needs the database name,
username, and the password. My procedures for handling this work but are
clunky and probably not considered to be best practices. From what I've
heard, using Chef is the best practice. However, Chef is complicated,
I'm having difficulty making sense of it.

In the source code for bsf_scrape (Ruby gem), I have functions in the
lib/bsf_scrape.rb file that do the following:
1.  Set the database name (stores it in a file)
2.  Get the database name (read it from a file)
3.  Set the path to the directory containing the username and password
(necessary for the production environment, as the database username is
different from the server username): Please note that while the database
name is the same in the development and production environments, the
username and password are different.
4.  Get the path to the directory containing the username and password
(production environment)
5.  Reads the username from a file (production environment)
6.  Reads the password from a file (production environment)

In the source code for bsf (Rails app), I have procedures that obtain
database parameters during the deployment process. Running the
script (config/deploy.rb) involves running the update script
(config/update.rb), that provides the database name, database username,
database password and retains these parameters in files for use by the
bsf_scrape Ruby gem.

I know this process is convoluted, but I can't replace it until I figure
out how to do it correctly in Chef. Are there any good Chef
tutorials/examples that will help me with this? My needs aren't that
complex at the moment, but most of the tutorials/examples I've looked at
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.