Reputation: 1413
Actually try to write wirst cookbook with chef-solo and I am look up to cookbook wordpress to initialize my own site.
But for few hours I couldn't find solution for this bug:
No resource or method named `template' for `Chef::Recipe "create_configs"'
On fragment:
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
with Vagrant file:
# -*- 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
Funny think is that resource "directory" working fine, but the same problem I have with use "execute".
Used cookbook wordpress and added all needed cookbooks and workend fine with this two resources.
I have version 11.10 of chef. Using Vagrant to create VirtualMachine
Any idea? Need help/clue what to do :/
Upvotes: 2
Views: 9711
Reputation: 664
you sure get that error if, i.e. you write "mod" instead of "mode" as just happened to me
Upvotes: 0
Reputation: 25009
While Mark's answer helped you fix your problem, the original issue you ran into where Chef threw the error message -
No resource or method named `template' for `Chef::Recipe "create_configs"'
is actually caused by the template
resource containing something that throws a NoMethodError
.
So:
template "#{project_config_dir}/database.php" do
# some code here
something_(like_a_node_attribute)_that_raises_no_method_error
end
If I had to guess, I would assume you didn't include the apache
cookbook in your run-list, since you most likely have all your app_db_config
attributes set somewhere.
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'],
}
)
Upvotes: 3
Reputation: 182
I have the same problem. I used this article as tutorial. After all I want to create own cookbook. I named it ruby and saved in site_cookbooks. I added default recipe with simple code:
execute "install_ruby_through_rvm" do
command "rvm install #{default['ruby']['install_version']}"
action :run
end
I have tried the solution that proposed by Mark O'Connor but I get only one result every time:
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"'
I don't understand what's wrong?
UPDATED
I'm just a fool:-) The problem was in a hash with attributes! The correct recipe:
execute "install_ruby_through_rvm" do
command "rvm install #{node['ruby']['install_version']}"
action :run
end
Upvotes: 1
Reputation: 78021
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:
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_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:
Upvotes: 1