0

I am trying to create a cookbook wrapper to deploy MySQL with Chef, but it seems that it does not insert the initial root password that I am setting in my cookbook.

mysql_client 'default' do
    version '5.6'
    action :create
end

if node['kaltiot_mysql']['deployServer'] == 'true'

    #-------------------------------------------
    # Create the database server and start it
    #-------------------------------------------
    mysql_service 'default' do
      port '3306'
      version '5.6'
      initial_root_password node['mysql']['initial_root_password']
      action [:create, :start]
    end

    #-------------------------------------------
    # Create the database and the user to access
    #-------------------------------------------
    include_recipe 'database::mysql'

    connection_params = {
      :host     => 'localhost',
      :username => 'root',
      :password => node['mysql']['initial_root_password']
    }

    mysql_database 'test' do
      connection connection_params
      action :create
    end

    mysql_database_user 'usertest' do
      connection connection_params
      password node['mysql']['initial_root_password']
      privileges [:all]
      action [:create, :grant]
    end

end

My environment is the following:

The cookbooks that I am using are the latest releases:

  • mysql 6.0.7
  • database 3.0.0

As the initial password is not set, the database part fails as it can not access the database.

The logs on the shell are the following:

 * bash[default :create initialize mysql database] action run[2015-01-16T10:03:03+00:00] INFO: Processing bash[default :create initialize mysql database] action run (/tmp/kitchen/cache/cookbooks/mysql/libraries/provider_mysql_service.rb line 143)
Installing MySQL system tables...       2015-01-16 10:03:03 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK

Filling help tables...
2015-01-16 10:03:06 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

 /usr/bin/mysqladmin -u root password 'new-password'
 /usr/bin/mysqladmin -u root -h default-centos-66.vagrantup.com password 'new-password'

Alternatively you can run:

 /usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

 cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

 cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

 http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

[2015-01-16T10:03:08+00:00] INFO: bash[default :create initialize mysql database] ran successfully

     - execute "bash"  "/tmp/chef-script20150116-2184-1tou5sq"
   * bash[default :create initial records] action nothing[2015-01-16T10:03:08+00:00] INFO: Processing bash[default :create initial records] action nothing (/tmp/kitchen/cache/cookbooks/mysql/libraries/provider_mysql_service.rb line 152)
(skipped due to action :nothing)
[2015-01-16T10:03:08+00:00] INFO: bash[default :create initialize mysql database] sending run action to bash[default :create initial records] (delayed)
   * bash[default :create initial records] action run[2015-01-16T10:03:08+00:00] INFO: Processing bash[default :create initial records] action run (/tmp/kitchen/cache/cookbooks/mysql/libraries/provider_mysql_service.rb line 152)
150116 10:03:08 mysqld_safe Logging to '/var/log/mysql-default/error.log'.
150116 10:03:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql-default
150116 10:03:12 mysqld_safe mysqld from pid file /var/run/mysql-default/mysqld.pid ended
[2015-01-16T10:03:12+00:00] INFO: bash[default :create initial records] ran successfully

- execute "bash"  "/tmp/chef-script20150116-2184-gjywc9"       

Anyone can bring some light why it is not setting that initial password?

Thanks in advance, -Enrique

Enrique Cordero
  • 33
  • 1
  • 1
  • 6

1 Answers1

0

... seems you didn't had a look at the mysql cookbook Readme: Quote from it:

Usage

Place a dependency on the mysql cookbook in your cookbook's metadata.rb

depends 'mysql', '~> 6.0' Then, in a recipe:

mysql_service 'default' do
  port '3306'
  version '5.5'  
  initial_root_password 'change me'
  action [:create, :start]
end

mysql_config 'default' do
  source 'mysite.cnf.erb'
  notifies :restart, 'mysql_service[default]'
  action :create 
end

The mysql_service resource ends up with mysql stopped, it is assumed there'll be a mysql_config resource after which will restart the service.

Tensibai
  • 15,557
  • 1
  • 37
  • 57
  • I though the configuration part was optional, otherwise it would set the default.... Anyway, I included that one and I get an error when trying to start. The logs are here http://pastebin.com/WjqDi0w2 – Enrique Cordero Jan 20 '15 at 13:39
  • nope, the notification is configured to restart, as later you may just have a configuration change, but it is needed anyway to finalize the mysql configuration. – Tensibai Jan 20 '15 at 13:41
  • Thanks, any idea what this "start" error could be related to? Too much time lost with this cookbook already :( – Enrique Cordero Jan 20 '15 at 13:53
  • This is not an error, it's an implementation feature, no trying to start an unconfigured mysql server, as you may not be able to restart it later anyway. The init.d service may try to shutdown the server cleanly (depending on the flavor of linux) by connecting to it, if it can't because of the initial configuration it will fail restarting it and can stay broken. – Tensibai Jan 20 '15 at 14:05
  • @EnriqueCordero to see why see the cookbook code [here](https://github.com/chef-cookbooks/mysql/blob/master/libraries/helpers.rb) and search for the `init_records_script` function. – Tensibai Jan 20 '15 at 14:08