简体   繁体   中英

Device not found error in Vagrant with Chef-Solo while testing cookbook

I have created some cookbooks in a repository which are executed in instances in AWS. I manually create an EBS volume in AWS at location dev/xvdb and then mount it using the following chef code:

mount "mount encrypted EBS volume at opt directory for app deployment" do
  action [:mount, :enable]
  device "/dev/xvdb"
  fstype "ext3"
  mount_point "/opt"
end

Now, in an effort to test the cookbooks locally, I have configured a vagrant box and trying to run the cookbook that contains the above code in it. I have the following Vagrant configuration:

Vagrant.configure("2") do |config|
  config.vm.box = "precise32"
  config.vm.provision "chef_solo" do |chef|
      chef.cookbooks_path = "cookbooks"
      chef.data_bags_path = "databags"
      chef.environments_path = "environments"
      chef.environment = "dev"
      chef.roles_path = "roles"
      chef.add_role("webapp")
  end
end

But as the Vagrant box does not have a /dev/xvdb folder path, it fails with:

==> default: Chef::Exceptions::Mount ==> default: ==> default: ----------------------- ==> default: ==> default: Device /dev/xvdb does not exist

How can I enable testing this locally on my vagrant box?

Add something like only_if { node['ec2'] } so it only converges that resource on actual EC2 machines. You can also use stuff from node['cloud'] or similar to check, or if you wanted to make it completely generic somehow, only_if { ::File.exist?('/dev/xvdb') } .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM