How to pass environment variables to test kitchen in .kitchen.yml

dami.max picture dami.max · Jan 25, 2016 · Viewed 7.3k times · Source

I am trying develop a cookbook to make a flask app work with gunicorn and nginx. I have been successful to the point that the app is running very well with a local sqlite database, see my cookbook at https://github.com/harrywang/flasky-cookbook. The flask app uses environment variables for sending emails such as: MAIL_USERNAME = os.environ.get('MAIL_USERNAME'), how I can pass those environment variables to the ubuntu virtual machines using test kitchen during kitchen converge?

Answer

coderanger picture coderanger · Jan 26, 2016

You can use Erb formatting in your .kitchen.yml:

provisioner:
  name: chef-solo
  attributes:
    mycookbook:
      mail_username: <%= ENV['MAIL_USERNAME'] %>

And then use node['mycookbook']['mail_username'] in your recipe to pass the value to the application.