Chef infra 没有名为'template';厨师
实际上,试着和厨师索洛一起写第一本烹饪书,我正期待着用wordpress来初始化我自己的网站 但有几个小时我找不到解决此错误的方法:Chef infra 没有名为'template';厨师,chef-infra,chef-solo,Chef Infra,Chef Solo,实际上,试着和厨师索洛一起写第一本烹饪书,我正期待着用wordpress来初始化我自己的网站 但有几个小时我找不到解决此错误的方法: No resource or method named `template' for `Chef::Recipe "create_configs"' 关于片段: template "#{project_config_dir}/database.php" do source "database.php.erb" mode 0440 owner "roo
No resource or method named `template' for `Chef::Recipe "create_configs"'
关于片段:
template "#{project_config_dir}/database.php" do
source "database.php.erb"
mode 0440
owner "root"
group node['apache']['group']
variables(
'dev' => {
'type' => app_db_config['type'],
'hostname' => app_db_config['hostname'],
'port' => app_db_config['port'],
'username' => app_db_config['user'],
'password' => app_db_config['password'],
'database' => app_db_config['dababase'],
}
)
action :create
end
使用流浪者文件:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# 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|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.network :private_network, ip: "192.168.33.11", :bridge => 'en1: Wi-Fi (AirPort)'
config.vm.synced_folder "/Users/Tom/Documents/vagrant/destination_server/public", "/home/vagrant/public"
config.vm.provider :virtualbox do |vb|
# Don't boot with headless mode
vb.gui = false
# Use VBoxManage to customize the VM. For example to change memory:
vb.customize ["modifyvm", :id, "--memory", "1024"]
end
config.vm.provision :shell, :inline => "/etc/init.d/networking restart"
config.vm.provision :shell, :inline => "sudo apt-get update -y"
config.vm.provision :shell, :inline => "sudo apt-get install ruby1.9.3 -y"
config.vm.provision :shell, :inline => "sudo apt-get install rubygems -y"
config.vm.provision :shell, :inline => "cd /home/vagrant && sudo ./postinstall.sh"
config.vm.provision "chef_solo" do |chef|
chef.add_recipe "apt"
chef.add_recipe "bazaar"
chef.json = {
"mysql" => {
"server_debian_password" => "root",
"server_root_password" => "root",
"server_repl_password" => "root"
},
"run_list" =>["recipe[mysql::server]"]
}
chef.add_recipe "site"
end
end
有趣的是,资源“目录”工作正常,但我使用“执行”时遇到了同样的问题
使用了CookbookWordPress并添加了所有需要的cookbooks和WorkEndFine
我有chef的11.10版。
使用Vagrant创建虚拟机
有什么想法吗?需要帮助/提示如何操作:/不清楚错误是什么,但您的流浪汉文件似乎过于复杂 我建议您使用omnibus插件来管理chef的安装,使用Berkself插件来管理烹饪书。举个例子,我建议:
site :opscode
cookbook "apt"
cookbook "bazaar"
cookbook "mysql"
cookbook "site", :path "cookbooks/site"
流浪汉档案
注意事项:
- shell provisioner被一个综合变量替换,该变量指示应安装哪个版本的chef
- add_recipe方法将为您构建运行列表
- 我也有同样的问题。我用这个作为教程。毕竟,我想创造自己的食谱。我把它命名为ruby,并保存在网站的烹饪书中。我用简单的代码添加了默认配方:
execute "install_ruby_through_rvm" do
command "rvm install #{default['ruby']['install_version']}"
action :run
end
我尝试过Mark O'Connor提出的解决方案,但每次只得到一个结果:
Relevant File Content:
----------------------
/tmp/vagrant-chef/chef-solo-1/cookbooks/ruby2/recipes/default.rb:
3: # Recipe:: default
4: #
5: # Copyright 2014, YOUR_COMPANY_NAME
6: #
7: # All rights reserved - Do Not Redistribute
8: #
9:
10>> execute "install_ruby_through_rvm" do
11: command "rvm install #{default['ruby']['install_version']}"
12: action :run
13: end 14:
[2014-02-10T21:50:01+00:00] ERROR: Running exception handlers
[2014-02-10T21:50:01+00:00] ERROR: Exception handlers complete
[2014-02-10T21:50:01+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-02-10T21:50:01+00:00] ERROR: No resource or method named `execute' for `Chef::Recipe "default"'
我不明白怎么了
已更新
我只是个傻瓜:-)问题出在属性的散列中!正确的配方:
execute "install_ruby_through_rvm" do
command "rvm install #{node['ruby']['install_version']}"
action :run
end
虽然Mark的回答帮助您解决了问题,但您遇到的原始问题是Chef抛出错误消息的地方-
No resource or method named `template' for `Chef::Recipe "create_configs"'
实际上是由模板
资源引起的,该资源包含抛出命名错误的内容
因此:
如果让我猜的话,我会假设您没有将apache
食谱包含在您的跑步列表中,因为您很可能在某个地方设置了所有app\u db\u config
属性
group node['apache']['group']
variables(
'dev' => {
'type' => app_db_config['type'],
'hostname' => app_db_config['hostname'],
'port' => app_db_config['port'],
'username' => app_db_config['user'],
'password' => app_db_config['password'],
'database' => app_db_config['dababase'],
}
)
如果你写的是“mod”而不是“mode”,你肯定会犯这个错误,就像刚刚发生在我身上的那样这解决了我的问题,但我不知道如何解决。在OS Meveric上使用gem安装Berkshelle
安装Berkshelle时会出现很多问题。最好从安装开始:gem安装minitar--install dir~/.vagrant.d/gems
但是现在我可以开始下一个工作了。Thanks@thomasso88你的原始版本可能是任何东西:chef的版本,你的烹饪书的版本和UbuntuMaveric(10.10)是一个非常古老的操作系统。。。。我很高兴它现在起作用了。Berkshelf和omnibus插件在处理vagrant时非常有用。您的下一个优势是chef zero插件:-)OConno-Yes-anything。对于excaple,我在执行时遇到了同样的问题,
操作:run`。当我添加这个时,问题解决了。我最近在一个已知的工作配方上看到了这一点。几分钟后重新运行chef client修复了它,所以我认为这是chef中的一个bug。)-:
template "#{project_config_dir}/database.php" do
# some code here
something_(like_a_node_attribute)_that_raises_no_method_error
end
group node['apache']['group']
variables(
'dev' => {
'type' => app_db_config['type'],
'hostname' => app_db_config['hostname'],
'port' => app_db_config['port'],
'username' => app_db_config['user'],
'password' => app_db_config['password'],
'database' => app_db_config['dababase'],
}
)