I am relatively new to chef and am trying to get my head around several concepts by using Vagrant and chef-solo to provision VirtualBox machines for a local development environment.
Currently, I have a webserver role which is basically the following 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]"
And a webapp role with the following run_list
"recipe[subversion]",
"recipe[my-app]"
All cookbooks are from opscode or community cookbooks, except my-app which is as follows (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
Everything works great until chef-client tries to run the mysql_database resource, at which point I get the following output:
[2014-06-17T15:32:19+00:00] ERROR: No resource or method named `mysql_database' for `Chef::Recipe "default"'
If I add database::mysql recipe to the run_list, it apparently automatically tries to connect with the default root password from mysql::server attributes.
I understand the "right" way to do this may be to specify the attributes in an attribute file, and put database::mysql in the runlist, but since I'm using this as an exercise to learn chef, I'd like to understand a) why my approach is not working and b) if it's possible to use the mysql_database resource by including the recipe rather than adding it to a runlist.