Pergunta

I've installed VirtualBox, Vagrant and chef-solo on my MBP laptop running Mountain Lion. I've downloaded recipes from opscode and have 'vagrant up' working. The VM is successfully create and I get a mostly working LAMP stack.

Where I am stuck is creating a database and user to access the database.

What I've done: Created a development folder that includes Vagrantfile and the directory cookbooks. In cookbooks I have

README.md
apache2
apt
aws
build-essential
database
hnnapp
mysql
openssl
php
postgresql
xfs
xml

'hnnapp' contains my own recipe to launch my virtual machine. I used knife to initialize the folder and then edited metadata.rb to include

depends "apt"
depends "apache2"
depends "database"
depends "mysql"
depends "xml"
depends "openssl"
depends "php"
depends "build-essential"

and in recipes/default.rb I have include

include_recipe "apt"
include_recipe "apache2"
include_recipe "xml"
include_recipe "openssl"
include_recipe "database::mysql"
include_recipe "mysql"
include_recipe "mysql::client"
include_recipe "mysql::server"
include_recipe "mysql::ruby"
include_recipe "php"
include_recipe "php::module_mysql"
include_recipe "apache2::mod_php5"
include_recipe "apache2::mod_rewrite"

apache_site "default" do
    enable true
end

mysql_database node['hnnapp']['database'] do
    connection  ({:host => 'localhost', :username => 'root', :password => node['mysql']['server_root_password']})
    action :create
end

mysql_database_user node['hnnapp']['db_username'] do
    connection  ({:host => 'localhost', :username => 'root', :password => node['mysql']['server_root_password']})
    password node['hnnapp']['db_password']
    database_name node['hnnapp']['database']
    privileges [:select, :update, :insert, :cretae, :delete]
    action :create
end

Finally, my Vagrantfile includes

config.vm.provision :chef_solo do |chef|
    chef.add_recipe "hnnapp"
    chef.json = {
      "hnnapp" => {
        "db_password" => "test", 
        "db_username" => "testuser",
        "database" => 'testdatabase'
      },
      "mysql" => {
        "server_root_password" => "098f6bcd4621d373cade4e832627b4f6",
        "server_debian_password" => "098f6bcd4621d373cade4e832627b4f6",
        "server_repl_password" => "098f6bcd4621d373cade4e832627b4f6"
      }
    }
  end

When I 'vagrant ssh' into the VM I see apache, php and mysql is installed. MySQL has no other databases except for test and information schema. I can use 'mysql' to get into mysql client, but I have no privileges to create any databases or users. sudo mysql doesn't work either.

I'd like to find out two things:

  1. Am I going about this the right way? Putting the right commands in the right files?
  2. What mistakes do I have in my scripts.
Foi útil?

Solução

Does it make any difference if you add :grant to your actions in the mysql_database_user block?

action [:create, :grant]

I found this tutorial quite helpful with provisioning mysql with a user and privileges, although I am still a bit confused with the directory structure of chef-solo.

http://misheska.com/blog/2013/06/23/getting-started-writing-chef-cookbooks-the-berkshelf-way-part2/

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top