Skip to content

Instantly share code, notes, and snippets.

@webcoyote
Created September 10, 2014 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webcoyote/7f7131e0619a6fc9206d to your computer and use it in GitHub Desktop.
Save webcoyote/7f7131e0619a6fc9206d to your computer and use it in GitHub Desktop.
Test kitchen configuration initialized by discovering the values from Chef-server
# test-kitchen YAML configuration file which discovers values from Chef environment
#
# Manual configuration got you down?
# Don't want to pollute your shell environment with a bunch of secrets?
# Why not load those values from Chef?!?
#
<%
require 'yaml'
ENVIRONMENT = >>> YOUR ENVIRONMENT NAME HERE, e.g. "project-test" <<<
def deep_symbolize(obj)
return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = deep_symbolize(v); memo} if obj.is_a? Hash
return obj.inject([]){|memo,v | memo << deep_symbolize(v); memo} if obj.is_a? Array
return obj
end
NODE ||= begin
# Load configuration from Chef
output = `knife environment show #{ENVIRONMENT} -f yaml`
abort "ERROR: Unable to read #{ENVIRONMENT} environment from Chef" if $? != 0
# The first line of the environment is "--- !ruby/object:Chef::Environment"
# which YAML doesn't like to load without requiring Chef; replace it
output.gsub!(/^---.+$/, "---")
# Get the node default attributes
deep_symbolize(YAML.load(output))[:default_attributes]
end
%>
---
driver:
name: vagrant
provisioner:
name: chef_zero
platforms:
- name: ubuntu-12.04
suites:
- name: default
run_list:
- recipe[project::default]
attributes:
project:
github_user: <%= NODE[:project][:github_user] %>
github_token: <%= NODE[:project][:github_token] %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment