Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 925
dami.max Avatar asked Jan 25 '16 22:01

dami.max


People also ask

Does Yaml support environment variables?

Environment variable substitution is supported in both the great_expectations. yml and config variables config_variables.

What is Kitchen Yml file?

kitchen. yml file is the main configuration file for kitchen. This file contains mainly 4 blocks driver, provisioner, platforms and suites. Driver: This is the name of driver that is used to create new node for testing. Provisioner: This is the chef provisioner to simulate test, chef-zero and chef-solo are the options.

What is test kitchen in Chef?

Test Kitchen is Chef's integrated testing framework. It enables writing test recipes, which will run on the VMs once they are instantiated and converged using the cookbook. The test recipes run on that VM and can verify if everything works as expected. ChefSpec is something which only simulates a Chef run.

What is kitchen converge?

A converge will leave the machine running and kitchen automatically uploads changes each converge so that one can iterate rapidly on configuration code. A lot of time and effort has gone into ensuring that the exit code of kitchen is always appropriate.


1 Answers

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.

like image 139
coderanger Avatar answered Sep 23 '22 08:09

coderanger