vagrantfile cookbook path - vagrant

I want to set the cookbook path to a certain place, so that I don't need to
modify the Vagrantfile everytime(after vagrant init).
I find Vagrantfile load several places, so I decide to set my cookbook path info
in ~/.vagrant.d/Vagrantfile,(this file is the 3rd of Vagrantfile Load Order) like:
...
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["D:/lib/chef/cookbooks"]
chef.add_recipe "dev::default"
end
...
but when I make a new vm, and modify Vagrantfile(this file is the 4th of Vagrantfile Load Order):
...
config.vm.provision :chef_solo do |chef|
chef.add_recipe "torch"
end
...
error:
[2013-02-28T03:23:36+00:00] ERROR: Running exception handlers
[2013-02-28T03:23:36+00:00] ERROR: Exception handlers complete
[2013-02-28T03:23:36+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-02-28T03:23:36+00:00] FATAL: Chef::Exceptions::CookbookNotFound: Cookbook torch not found. If
you're loading torch from another cookbook, make sure you configure the dependency in your metadata
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
but I am sure the specific cookbook is under my cookbook path.

Try the following steps:
- Create a folder cookbooks in the vagrantfile's directory
- checkout the cookbooks to this directory
- add the following to your vagrantfile
chef.cookbooks_path = ["cookbooks"]
hope to have helped

Related

confused with berkshelf, chef and vagrant

I've took a look on BerkShelf documentation. I've been able to figure out it stands for managing cookbook dependencies. So, guess I'd like to build a machine with java. I've first generated my custom cookbook:
chef generate cookbook custom-java
My Berksfile is:
source 'https://supermarket.chef.io'
metadata
cookbook 'java'
and my metadata.rb is:
name 'custom-java'
...
version '0.1.0'
After that, I've simply run berks install, so all dependencies have been resolved and located under ~\.berkshelf\cookbooks.
Nevertheless, I don't quite figure out how to use my custom-java into my vagrant configuration. What do I need to do in order for vagrant to provistion this cookbook into my machines?
My vagrant structure is:
VagrantFile
├───chef
│ ├───cookbooks
│ │ ├───(((1))) <<<<<<<<<<<<<<<<<<<<<<
│ ├───roles
│ │ ├───java-dev-workstation.rb
Vagrantfile content is:
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.provision "chef_solo" do |chef|
chef.roles_path = "chef/roles"
chef.cookbooks_path = "chef/cookbooks"
chef.add_role "java-dev-workstation"
end
end
And java-dev-workstation.rb:
name "java-dev-workstation"
default_attributes(
# Because it's Oracle, we need to agree to the terms and conditions.
:custom-java => { >>>>>>>>> (((2)))
:install_flavor => 'oracle',
:jdk_version => '8',
:accept_license_agreement => true,
:oracle => { "accept_oracle_download_terms" => true }
}
)
run_list(
"recipe[java]"
)
I'm using Chef 12.18.31.
On (((1))): Do I need to "import" my custom-java cookbook, how? Where is it located?
On (((2))): How should I configure java?
EDIT
I've set chef.cookbooks_path:
config.vm.provision "chef_solo" do |chef|
chef.roles_path = "chef/roles"
chef.cookbooks_path = 'D:\projects\living\vagrant\production\berk\custom-java'
chef.add_role "java-dev-workstation"
end
EDIT2
Nevertheless, custom-java dependencies are not resolved now:
================================================================================
Error Resolving Cookbooks for Run List:
================================================================================
Missing Cookbooks:
------------------
No such cookbook: yum
Expanded Run List:
------------------
* custom-java
Platform:
---------
x86_64-linux
My metadata.rb content is:
name 'berk'
...
version '0.1.0'
supports 'centos'
depends 'yum'
Currently, all dependencies are located in ~/.berkshelf/cookbooks. It seems shef-solo is not looking for in it...
You did take it backward for a wrapper cookbook pattern, your custom_java should depends on java and change its default behavior (overriding node attributes).
Your custom-java metadata.rb should contain a line like this, what is in the berksfile will never be interpreted by the chef-client run, it's an outside dependency resolver to create coherent bundles.
depends 'java', '~> 1.47'
And the default.rb a line
include_recipe 'java'
Then your Berksfile can omit the cookbook line (unless you're pulling a version elsewhere than the source at top)
Next your role should use custom-java as recipe and not java, then the chef-client run (the vagrant part before edit sounds ok and should pull both cookbooks) will compute attributes from the java coobooks, overwrite those defined in custom-java and you should end up with the desired behavior.
Alternatively, you can just set the runlist to custom-java and avoid the role altogether, that will works.
I highly recommend you to go through all the tutorials on https://learn.chef.io to get a better overview.

what is the proper way to override chef recipe attributes?

I am adding this Solr Chef recipe an existing vagrant box . I want to override the version attribute here . Do I override these variables in one of the json files or it has to be overridden in the recipe attributes file itself?
For your use case it's ok to override it in Vagrantfile directly. Check more info about chef solo and vagrant here.
tldr;
Just provide chef.json option with attributes in your Vagrantfile like:
Vagrant.configure("2") do |config|
config.vm.provision "chef_solo" do |chef|
# ...
chef.json = {
"solr" => {
"version" => "4.6.1"
}
}
end
end
In general practise it's common to set attributes inside roles, or by creating wrapper cookbooks around community ones, and with that there is no need for changing original source code.

"no such file to load -- chef/provider/lwrp_base" when trying to run mysql cookbook via Vagrant using chef-solo provisioner

Alright so I am using a bunch of technologies that are new to me here, so I'm not sure how to slice up the problem. I have a little experience with vagrant, and am trying to learn Chef now.
I've cloned this cookbook: https://github.com/opscode-cookbooks/mysql to my ./cookbooks/mysql directory. I'm trying to run that cookbook via Vagrant with this Vagrantfile:
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
# Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.define "mysql" do |mysql|
mysql.vm.network :hostonly, "192.168.33.12"
mysql.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "mysql"
chef.json = {
:server => {
version: '5.6',
port: '3307',
data_dar: '/data-mysql',
allow_remote_root: true,
remove_anonymous_Users: true,
remove_test_database: true
}
}
end
end
end
When I run 'vagrant up mysql' I get this output:
Running chef-solo...
stdin: is not a tty
[2014-05-07T17:20:23+00:00] INFO: *** Chef 10.14.2 ***
[2014-05-07T17:20:23+00:00] INFO: Run List is []
[2014-05-07T17:20:23+00:00] INFO: Run List expands to []
[2014-05-07T17:20:23+00:00] INFO: Starting Chef Run for precise64
[2014-05-07T17:20:23+00:00] INFO: Running start handlers
[2014-05-07T17:20:23+00:00] INFO: Start handlers complete.
================================================================================
Recipe Compile Error in /tmp/vagrant-chef-2/chef-solo-1/cookbooks/mysql/libraries/provider_mysql_service_omnios.rb
================================================================================
LoadError
---------
no such file to load -- chef/provider/lwrp_base
Cookbook Trace:
---------------
/tmp/vagrant-chef-2/chef-solo-1/cookbooks/mysql/libraries/provider_mysql_service_omnios.rb:1
Why is this failing? I wonder if the mysql cookbook has a dependency on another cookbook that should provide the 'chef/provider/lwrp_base' file.
UPDATE: The issue could be that Vagrant is running Chef 10.14.2, and the cookbook is marked as requiring Chef 11 here (http://community.opscode.com/cookbooks/mysql).
There are quite a few files referencing LWRP, shown here:
> gci .\cookbooks * -rec | select-string lwrp
cookbooks\mysql\CHANGELOG.md:320:- [COOK-684] remove mysql_database LWRP
cookbooks\mysql\libraries\provider_mysql_client.rb:5: class MysqlClient < Chef::Provider::LWRPBase
cookbooks\mysql\libraries\provider_mysql_client_debian.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_client_fedora.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_client_omnios.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_client_rhel.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_client_smartos.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_client_ubuntu.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_service.rb:5: class MysqlService < Chef::Provider::LWRPBase
cookbooks\mysql\libraries\provider_mysql_service_debian.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_service_fedora.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_service_omnios.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_service_rhel.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_service_smartos.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\provider_mysql_service_ubuntu.rb:1:require 'chef/provider/lwrp_base'
cookbooks\mysql\libraries\resource_mysql_client.rb:1:require 'chef/resource/lwrp_base'
cookbooks\mysql\libraries\resource_mysql_client.rb:5: class MysqlClient < Chef::Resource::LWRPBase
cookbooks\mysql\libraries\resource_mysql_service.rb:1:require 'chef/resource/lwrp_base'
You can overcome this using the vagrant omnibus plugin
Just run 'vagrant plugin install vagrant-omnibus' to add it, and add 'config.omnibus.chef_version = :latest' to the top of your vagrantfile, like so
Vagrant.configure("2") do |config|
config.omnibus.chef_version = :latest
...
end
In the directory above your cookbooks, this may show what is
referencing lwrp:
find cookbooks -exec grep lwrp {} \; -print
Ok, the problem was that my vagrant box had an older version of Ruby and Chef installed. It all works now, the source is at https://github.com/fschwiet/helloVagrant/tree/ceafdc9916e788136ae79f20722e77d76e2f1eef

Vagrant not able to find home/vagrant/hiera.yaml

I have inherited a python app that uses Puppet, Vagrant and VirtualBox to provision a local Centos test machine.
This app was written on Mac and I'm developing on Windows.
When I run vagrant up I see a large list of command line errors, the most relevant of which is:
Running Puppet with site.pp..
Warning: Config file /home/vagrant/hiera.yaml not found, using Hiera defaults
WARN: Fri Apr 25 16:32:24 +0100 2014: Not using Hiera::Puppet_logger. It does not report itself to b
e suitable.
I know what Hiera is, and why it's important, but I'm not sure how to fix this.
The file hiera.yaml is present in the repo but it's not found at home/vagrant/hiera.yaml, instead it's found at ./puppet/manifests/hiera.yaml.... Similarly if I ssh into the box, there is absolutely nothing whatsoever inside home/vagrant but I can find this file when I look in /tmp
So I'm confused, is vagrant looking inside the Virtual box and expecting this file to be found at home/vagrant/hiera.yaml? Or have I inherited an app that did not work properly in the first place? I'm really stuck here and I can't get in touch with the original dev.
Here are some details from my Vagrantfile:
Vagrant.configure("2") do |config|
# Base box configuration ommitted
# Forwarded ports ommitted
# Statically set hostname and internal network to match puppet env ommitted
# Enable provisioning with Puppet standalone
config.vm.provision :puppet do |puppet|
# Tell Puppet where to find the hiera config
puppet.options = "--hiera_config hiera.yaml --manifestdir /tmp/vagrant-puppet/manifests"
# Boilerplate Vagrant/Puppet configuration
puppet.module_path = "puppet/modules"
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "site.pp"
# Custom facts provided to Puppet
puppet.facter = {
# Tells Puppet that we're running in Vagrant
"is_vagrant" => true,
}
end
# Make the client accessible
config.vm.synced_folder "marflar_client/", "/opt/marflar_client"
end
It's really strange.
There's this puppet.options line that tells Puppet where to look for hiera.yaml and currently it simply specifies the file name. Now, when you run vagrant up, it mounts the current directory (the one that has the Vagrantfile in it) into /vagrant on the guest machine. Since you're saying hiera.yaml is actually found in ./puppet/manifests/hiera.yaml, I believe you want to change the puppet.options line as follows:
puppet.options = "--hiera_config /vagrant/puppet/manifests/hiera.yaml --manifestdir /tmp/vagrant-puppet/manifests"
To solve this warning, you may first try to check from where this file is referenced, i.e.:
$ grep -Rn hiera.yaml /etc/puppet
/etc/puppet/modules/stdlib/spec/spec_helper_acceptance.rb:13: on hosts, '/bin/touch /etc/puppet/hiera.yaml'
/etc/puppet/modules/mysql/spec/spec_helper_acceptance.rb:34: shell("/bin/touch #{default['puppetpath']}/hiera.yaml")
In this case it's your vagrant file.
You may also try to find the right path to it via:
sudo updatedb && locate hiera.yaml
And either follow the #EvgenyChernyavskiy suggestion, create a symbolic link if you found the file:
sudo ln -vs /etc/hiera.yaml /etc/puppet/hiera.yaml
or create the empty file (touch /etc/puppet/hiera.yaml).
In your case you should use the absolute path to your hiera.yaml file, instead of relative.
The warning should be gone.

How do I use Chef data bags from my Vagrantfile?

I am attempting to use Fnichol's Chef User recipe with Vagrant to automatically create a specific user account when I run vagrant up. Because I setup this user for nearly every project that I work on, I'd like to store the user data in a data bag that I am loading from a JSON file that I can re-use on multiple projects.
This is what my Vagrantfile currently looks like: http://pastebin.com/b0riZZCz
It fails with the error:
[2014-01-20T16:09:39+00:00] ERROR: could not find recipe ben for cookbook user
I have created a data bag called "users" and inside that data bag I've created a data bag item named "ben" from the following JSON:
{
"id": "ben",
"comment": "Ben Harold",
"groups": ["admin", "www-data"],
"ssh_keys": ["...longtextstring..."],
"ssh_keygen": false
}
I'm attempting to follow the usage instructions at http://fnichol.github.io/chef-user/ to:
Import the Chef Users recipe
Tell the Chef Users recipe to create the user ben from the data bag users
It appears to me that the Chef provisioning syntax from within a Vagrantfile is considerably different than the syntax that is presented in most of the available documentation. For example:
"Simply include recipe[user] in your run_list and the user_account
resource will be available."
I'm confused as to the definition of run_list, as well as the recipe[user] syntax. From the Vagrant documentation, it seems that my run_list is everything in this block:
config.vm.provision :chef_solo do |chef|
chef.add_recipe "apt"
...etc...
end
However, I've also found references to chef.run_list being defined within that block, although I have not been able to find any documentation specifically referring to chef.run_list.
Question 1
Is the run_list simply the code within the config.vm.provision :chef_solo do |chef| block, or is it something else?
Question 2
Where is the documentation for chef.run_list? I'm not looking for the documentation on the Chef site. The syntax seems completely different to me.
I've been messing with this for several hours. I've tried a bunch of stuff that does not work. I am able to import the Chef User recipe, but I haven't been able to figure out how to tell Chef to run the user recipe against the data bag item "ben".
Question 3
How do I get Chef to run the user recipe with the data bag item "ben"? Or am I doing it completely wrong?
Answer 1
No, run_list is actually just an array of strings, that represent recipes/roles that should be run on Vagrant Machine. And add_recipe adds new recipes into this list. Like that:
config.vm.provision :chef_solo do |chef|
[...]
chef.add_recipe 'cookbook::recipe' #now run_list has it in
chef.add_role 'myrole' #now run_list has a role too
#adding more recipes from ENV variable, just as example
chef.run_list += ENV['CHEF_RUN_LIST'].split ',' if ENV.has_key? 'CHEF_RUN_LIST'
[...]
end
Answer 2
You are editing Vagrantfile, so documentation is on Vagrant site
Answer 3
You need to tell Vagrant where are your cookbooks, data bags and roles.
config.vm.provision :chef_solo do |chef|
[...]
chef.cookbooks_path = 'cookbooks' #paths are relative to Vagrantfile location
chef.roles_path = 'roles'
chef.data_bags_path = 'data_bags'
[...]
end

Resources