I am newbie to the chef and its overall eco system, just has an experiment I trying to use mysql cookbook and trying to create a database and set username and password of the same. I am not able to figure out how to get this things done. I have set up my own chef-server on aws ec2 ubuntu instance. Kindly help me out.
Checkout the mysql_test cookbook. where it uses resource mysql_database_user
provided from the database cookbook.
Here's the code sample:
include_recipe 'mysql::server'
mysql_connection = {:host => "localhost", :username => 'root',
:password => node['mysql']['server_root_password']}
mysql_database node['mysql_test']['database'] do
connection mysql_connection
action :create
end
mysql_database_user node['mysql_test']['username'] do
connection mysql_connection
password node['mysql_test']['password']
database_name node['mysql_test']['database']
host 'localhost'
privileges [:select,:update,:insert, :delete]
action [:create, :grant]
end
Notice that you need to depend on the database cookbook and the mysql cookbook, and set the following node attributes:
default['mysql_test']['database']
- mysql database namedefault['mysql_test']['username']
- mysql database user namedefault['mysql_test']['password']
- mysql database user password