我对厨师比较陌生,我试图通过使用Vagrant和chef-solo为本地开发环境配置VirtualBox机器来解决几个概念。
目前,我有一个webserver角色,基本上是以下run_list:
"role[base]",
"recipe[php]",
"recipe[php::module_mysql]",
"recipe[apache2]",
"recipe[apache2::mod_php5]",
"recipe[apache2::mod_rewrite]",
"recipe[mysql-chef_gem]",
# "recipe[database]",
# "recipe[mysql::server]",
# "recipe[database::mysql]"
带有以下run_list的webapp角色
"recipe[subversion]",
"recipe[my-app]"
所有食谱都来自opscode或社区食谱,除了my-app,如下(default.rb):
include_recipe "mysql::server"
include_recipe "mysql::client"
include_recipe "database"
include_recipe "database::mysql"
env = data_bag_item("environments",node.chef_environment)
subversion "MyApp" do
repository env['app']['svn']['repo']
revision "HEAD"
svn_username env['app']['svn']['username']
svn_password env['app']['svn']['password']
destination env['app']['document_root']
action :sync
end
# Set up the Apache virtual host
web_app env['app']['name'] do
server_name env['app']['name']
docroot env['app']['document_root']
template "my-app-apache.conf.erb"
end
mysql_service 'default' do
allow_remote_root true
server_root_password env['mysql']['root_password']
action :create
end
mysql_database 'default' do
database_name env['app']['db']['name']
connection(
:host => 'localhost',
:username => 'root',
:password => env['mysql']['root_password']
)
action :create
end
在Chef-client尝试运行mysql_database资源之前,一切都很有效,此时我得到以下输出:
[2014-06-17T15:32:19+00:00] ERROR: No resource or method named `mysql_database' for `Chef::Recipe "default"'
如果我将database :: mysql配方添加到run_list,它显然会自动尝试使用mysql :: server属性中的默认root密码进行连接。
我理解"对"这样做的方法可能是在属性文件中指定属性,并将database :: mysql放在运行列表中,但由于我将此作为练习来学习厨师,我想了解一下)为什么我的方法不起作用b)如果可以通过包含配方而不是将其添加到运行列表来使用mysql_database资源。
答案 0 :(得分:2)
该资源来自数据库cookbook:https://github.com/opscode-cookbooks/database。您需要将database
cookbook添加到metadata.rb并重新配置以访问mysql_database
资源。