2

实际上尝试用 chef-solo 编写 wirst 食谱,我正在查找食谱 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 "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

有趣的想法是资源“目录”工作正常,但我在使用“执行”时遇到了同样的问题。

使用食谱 wordpress 并添加了所有需要的食谱,并且使用这两个资源可以很好地工作。

我有 11.10 版的厨师。使用 Vagrant 创建虚拟机

任何想法?需要帮助/提示该怎么做:/

4

4 回答 4

3

虽然马克的回答帮助您解决了问题,但您遇到的原始问题是厨师抛出错误消息 -

No resource or method named `template' for `Chef::Recipe "create_configs"'

实际上是由template包含抛出NoMethodError.

所以:

template "#{project_config_dir}/database.php" do
  # some code here
  something_(like_a_node_attribute)_that_raises_no_method_error
end

如果我不得不猜测,我会假设您没有将apache食谱包含在您的运行列表中,因为您很可能在app_db_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'],
    } 
  )
于 2014-02-18T03:28:33.430 回答
1

It's not clear what the error is, but your vagrant file appears to be unnecessarily complicated.

I would suggest you use the omnibus plugin to mange the installation of chef and the Berkshelf plugin to manage cookbooks. For an example I suggest:

Suggested edits

Berksfile

This file is require by Berkshelf and lists your cookbook dependencies. These will be automatically download from the community site. Here I'm assuming that the custom "site" cookbook is located under a cookbooks sub-directory:

site :opscode

cookbook "apt"
cookbook "bazaar"
cookbook "mysql"
cookbook "site", :path "cookbooks/site"

Vagrantfile

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Box   
  config.vm.box = "precise32"
  config.vm.box_url = "http://files.vagrantup.com/precise32.box"

  # Plugins
  config.berkshelf.enabled = true
  config.omnibus.chef_version = :latest

  # Network
  config.vm.network :private_network, ip: "192.168.33.11", :bridge => 'en1: Wi-Fi (AirPort)'

  # Storage
  config.vm.synced_folder "/Users/Tom/Documents/vagrant/destination_server/public", "/home/vagrant/public"

  # Virtualbox
  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

  # Chef solo provisioning
  config.vm.provision "chef_solo" do |chef|
    chef.add_recipe "apt"
    chef.add_recipe "bazaar"
    chef.add_recipe "mysql::server"
    chef.add_recipe "site"

    chef.json = {
      "mysql" => {
        "server_debian_password" => "root",
        "server_root_password" => "root",
        "server_repl_password" => "root"
      }
    }
  end    
end

Notes:

  • The shell provisioner is replaced by a omnibus variable indicating which version of chef should be installed
  • The add_recipe methods will construct the run list for you.
于 2014-02-09T01:18:16.337 回答
1

我也有同样的问题。我用这篇文章作为教程。毕竟我想创建自己的食谱。我将它命名为ruby​​ 并保存在site_cookbooks中。我用简单的代码添加了默认配方:

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
于 2014-02-10T22:17:18.667 回答
0

如果你写的是“mod”而不是“mode”,你肯定会得到那个错误,就像我刚刚发生的那样

于 2014-02-21T12:26:19.423 回答