Skip to content

Instantly share code, notes, and snippets.

@berngp
Created March 16, 2012 23:57
Show Gist options
  • Save berngp/2053728 to your computer and use it in GitHub Desktop.
Save berngp/2053728 to your computer and use it in GitHub Desktop.
Vagrant, Chef-Solo and Data_Bags
#!/usr/bin/env ruby
Vagrant::Config.run do |config|
# Web App Servers
config.vm.define :app do |app_config|
app_config.vm.box = "centos-6"
app_config.vm.network :hostonly, "33.33.33.30"
app_config.vm.share_folder("tomcat-gz-path", "/tmp/archive/tomcat", "../../archives/tomcat")
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["../../cookbooks", "cookbooks"]
chef.roles_path = "roles"
chef.data_bags_path = "data_bags"
chef.add_recipe 'ign-tomcat'
chef.json.merge!(
{
:java => {
:install_flavor => "sun",
:version => "6u25"
},
:tomcat => {
:java => {
:xopt => {
:min_heap => "64m",
:max_heap => "128m"
},
:run_mode => "Staging"
},
:users => {
:group => "tomcat",
:user => "tomcat-app",
:group_data_bag => "tomcat",
:users_data_bag => "tomcat-users"
},
:group_dBag => "tomcat",
:user_dBag => "tomcat-users"
},
:apps => {
:profiles => [
{
:name => "demo-app",
:group_id => "demo-group",
:version => "1.0",
:context => "demo",
:enabled => true
},
{
:name => "orinoco",
:group_id => "com.ign",
:version => "3.0.3",
:remote_base => "http://maven.ign.com/nexus/content/repositories/releases/",
:context => "orinoco#v3",
:enabled => true
}
]
}
}
)
end
end
end

The important thing about the Vagrant file is the line that reads chef.data_bags_path = "data_bags". The ign-tomcat recipe uses some Data Bags e.g. tomcat_group_details = data_bag_item('groups', 'tomcat') If we look at the working Dir..

$ ls -l
total 8
-rw-rw-r--  1 bpalacio  staff  2807 Mar 16 16:29 Vagrantfile
drwxrwxr-x  2 bpalacio  staff    68 Mar 15 17:31 cookbooks
drwxrwxr-x  7 bpalacio  staff   238 Mar 14 23:01 data_bags
drwxr-xr-x  2 bpalacio  staff    68 Mar 15 17:18 roles

and we cat data_bags/groups/tomcat.json we get:

{
	"id": "tomcat",
	"gid": 270
}

I had trouble with "id":"tomcat-server" for some strange reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment