简体   繁体   English

测试食谱时,Chef-Solo在Vagrant中找不到设备错误

[英]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. 我在存储库中创建了一些食谱,这些食谱在AWS实例中执行。 I manually create an EBS volume in AWS at location dev/xvdb and then mount it using the following chef code: 我在AWS的位置dev/xvdb处手动创建一个EBS卷,然后使用以下厨师代码安装它:

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配置:

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: 但是由于Vagrant框没有/dev/xvdb文件夹路径,因此它失败并显示:

==> default: Chef::Exceptions::Mount ==> default: ==> default: ----------------------- ==> default: ==> default: Device /dev/xvdb does not exist ==>默认:Chef :: Exceptions :: Mount ==>默认:==>默认:----------------------- ==>默认: ==>默认值:设备/ dev / xvdb不存在

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. 添加诸如only_if { node['ec2'] }以便仅在实际的EC2计算机上聚合该资源。 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') } . 您还可以使用来自node['cloud']或类似内容的内容进行检查,或者如果您想使其完全通用,则可以使用only_if { ::File.exist?('/dev/xvdb') }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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