

【質問】

[code]

    $ bundle exec knife solo cook ノード名
    
[/code]

で以下の通りエラーが発生が出る

> Error executing action `create` on resource 'mysql_database[aws]'

*現状databaseを使わないレシピは動いています

【やりたいこと】  
opscodeのdatabaseを使ってrecipeを書きたい  
（次のレシピではデータベースを作成しようとしているだけです）  
*公式  
<https://github.com/opscode-cookbooks/database/blob/master/README.md>

【レシピ】

## ./Berkshelf

[code]

    source "https://api.berkshelf.com"
    cookbook "mysql2_chef_gem"
    cookbook "database"
    cookbook "yum"
    
[/code]

## node/ノード.jsonファイル

[code]

    {
      "run_list": [
        "recipe[sample]"
      ],
      "automatic": {
        "ipaddress": "ノード名"
      }
    }
    
[/code]

## site-cookbooks/sample/metadata.rb

[code]

    name             'sample'
    maintainer       'YOUR_COMPANY_NAME'
    maintainer_email 'YOUR_EMAIL'
    license          'All rights reserved'
    description      'Installs/Configures mysql'
    long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
    version          '0.1.0'
    depends 'database'
    
[/code]

## site-cookbooks/sample/recipes/default.rb

[code]

    mysql_connection_info = {
      :host     => '127.0.0.1',
      :username => 'root',
      :password => 'パスワード'
    }
    mysql_database "aws" do
      connection mysql_connection_info
      action :create
    end
    
[/code]

【環境】  
Mac OSX 10.9.5  
Chef Development Kit Version: 0.4.0  
Chef: 12.0.3  
Bundler version 1.7.11  
database (4.0.2)  
chefの流し込んでいる先はAmazon Linux(2014 9)です

【その他】  
海外サイト等でもヒントになりそうな情報がありましたら  
ご指摘頂ければと思います。

【エラー】

> mysql_database[aws] action create
> ================================================================================  
>  Error executing action `create` on resource 'mysql_database[aws]'
> ================================================================================
>
> ## LoadError
>
> cannot load such file -- mysql2
>
> ## Cookbook Trace:
>
> /home/ec2-user/chef-
> solo/cookbooks-2/database/libraries/provider_database_mysql.rb:103:in
> `test_client'  
>  /home/ec2-user/chef-
> solo/cookbooks-2/database/libraries/provider_database_mysql.rb:37:in`block
> in '
>
> ## Resource Declaration:
>
> # In /home/ec2-user/chef-solo/cookbooks-3/sample/recipes/default.rb
>
> 15: mysql_database "aws" do  
>  16: connection mysql_connection_info  
>  17: action :create  
>  18: end  
>  19:
>
> ## Compiled Resource:
>
> # Declared in /home/ec2-user/chef-
> solo/cookbooks-3/sample/recipes/default.rb:15:in `from_file'
>
> mysql_database("aws") do  
>  provider Chef::Provider::Database::Mysql  
>  action [:create]  
>  retries 0  
>  retry_delay 2  
>  guard_interpreter :default  
>  database_name "aws"  
>  cookbook_name :sample  
>  recipe_name "default"  
>  connection {:host=>"127.0.0.1", :username=>"root", :password=>"パスワード"}  
>  end
>
> Running handlers:  
>  [2015-02-15T08:20:08+00:00] ERROR: Running exception handlers  
>  Running handlers complete  
>  [2015-02-15T08:20:08+00:00] ERROR: Exception handlers complete  
>  [2015-02-15T08:20:08+00:00] FATAL: Stacktrace dumped to
> /var/chef/cache/chef-stacktrace.out  
>  Chef Client failed. 0 resources updated in 1.391575845 seconds  
>  [2015-02-15T08:20:08+00:00] ERROR: mysql_database[aws] (sample::default
> line 15) had an error: LoadError: cannot load such file -- mysql2  
>  [2015-02-15T08:20:08+00:00] FATAL: Chef::Exceptions::ChildConvergeError:
> Chef run process exited unsuccessfully (exit code 1)

* * *

【追記分】

## Berksfile

[code]

    source "https://api.berkshelf.com"
    cookbook "mysql2_chef_gem"
    cookbook "database"
    cookbook "yum"
    
[/code]

## site-cookbooks/sample/metadata.rb

[code]

    name             'sample'
    maintainer       'YOUR_COMPANY_NAME'
    maintainer_email 'YOUR_EMAIL'
    license          'All rights reserved'
    description      'Installs/Configures mysql'
    long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
    version          '0.1.0'
    
    depends 'mysql2_chef_gem'
    depends 'database'
    
[/code]

## site-cookbooks/sample/attributes/default.rb

[code]

    default['mysql']['version']='5.5'
    
[/code]

## site-cookbooks/sample/recipes/default.rb

[code]

    #
    # Cookbook Name:: mysql
    # Recipe:: default
    #
    # Copyright 2014, YOUR_COMPANY_NAME
    #
    # All rights reserved - Do Not Redistribute
    #
    mysql2_chef_gem 'default' do
      client_version node['mysql']['version'] if node['mysql']
      action :install
    end
    
    mysql_connection_info = { 
      :host     => '127.0.0.1',
      :username => 'root',
      :password => 'パスワード' 
    }
    
    mysql_database "aws" do
      connection mysql_connection_info
      action :create
    end
    
[/code]

## Aws側のLinuxのMysqlバージョン

[code]

    Server version: 5.5.40 MySQL Community Server (GPL)
    
[/code]

【エラー】

> Running Chef on aws_controller...  
>  Checking Chef version...  
>  Installing Berkshelf cookbooks to 'cookbooks'...  
>  Resolving cookbook dependencies...  
>  Using apt (2.6.1)  
>  Using build-essential (2.1.3)  
>  Using chef-sugar (2.5.0)  
>  Using database (4.0.2)  
>  Using mariadb (0.2.12)  
>  Using mysql (6.0.13)  
>  Using mysql2_chef_gem (1.0.1)  
>  Using openssl (2.0.2)  
>  Using postgresql (3.4.14)  
>  Using rbac (1.0.2)  
>  Using resource-control (0.1.1)  
>  Using smf (2.2.1)  
>  Using yum (3.5.2)  
>  Using yum-epel (0.6.0)  
>  Using yum-mysql-community (0.1.12)  
>  Vendoring apt (2.6.1) to パス/cookbooks/apt  
>  Vendoring build-essential (2.1.3) to パス/cookbooks/build-essential  
>  Vendoring chef-sugar (2.5.0) to パス/cookbooks/chef-sugar  
>  Vendoring database (4.0.2) to パス/cookbooks/database  
>  Vendoring mariadb (0.2.12) to パス/cookbooks/mariadb  
>  Vendoring mysql (6.0.13) to パス/cookbooks/mysql  
>  Vendoring mysql2_chef_gem (1.0.1) to パス/cookbooks/mysql2_chef_gem  
>  Vendoring openssl (2.0.2) to パス/cookbooks/openssl  
>  Vendoring postgresql (3.4.14) to パス/cookbooks/postgresql  
>  Vendoring rbac (1.0.2) to パス/cookbooks/rbac  
>  Vendoring resource-control (0.1.1) to パス/cookbooks/resource-control  
>  Vendoring smf (2.2.1) to パス/cookbooks/smf  
>  Vendoring yum (3.5.2) to パス/cookbooks/yum  
>  Vendoring yum-epel (0.6.0) to パス/cookbooks/yum-epel  
>  Vendoring yum-mysql-community (0.1.12) to パス/cookbooks/yum-mysql-community  
>  Uploading the kitchen...  
>  Generating solo config...  
>  Running Chef...  
>  [2015-02-15T14:50:52+00:00] WARN:
>
> * * *
>
> SSL validation of HTTPS requests is disabled. HTTPS connections are still  
>  encrypted, but chef is not able to detect forged replies or man in the
> middle  
>  attacks.
>
> To fix this issue add an entry like this to your configuration file:
>
> ```  
>  # Verify all HTTPS connections (recommended)  
>  ssl_verify_mode :verify_peer
>
> # OR, Verify only connections to chef-server  
>  verify_api_cert true  
>  ```
>
> To check your SSL configuration, or troubleshoot errors, you can use the  
>  `knife ssl check` command like so:
>
> `  
>  knife ssl check -c /home/ec2-user/chef-solo/solo.rb  
>  `
>
> * * *
>
> Starting Chef Client, version 11.16.4  
>  Compiling Cookbooks...  
>  Converging 2 resources  
>  Recipe: sample::default  
>  * mysql2_chef_gem[default] action install  
>  Recipe: build-essential::_rhel  
>  * package[autoconf] action install (up to date)  
>  * package[bison] action install (up to date)  
>  * package[flex] action install (up to date)  
>  * package[gcc] action install (up to date)  
>  * package[gcc-c++] action install (up to date)  
>  * package[kernel-devel] action install (up to date)  
>  * package[make] action install (up to date)  
>  * package[m4] action install (up to date)  
>  * package[patch] action install (up to date)  
>  * mysql_client[default] action create
[code]

>
> ================================================================================
>      Error executing action `create` on resource 'mysql_client[default]'
>
> ================================================================================
>  
>      NoMethodError
>      -------------
>      undefined method `[]' for nil:NilClass
>  
>      Cookbook Trace:
>      ---------------
>      /home/ec2-user/chef-solo/cookbooks-2/mysql/libraries/helpers.rb:287:in
> `package_name_for'
>      /home/ec2-user/chef-solo/cookbooks-2/mysql/libraries/helpers.rb:319:in
> `client_package'
>      /home/ec2-user/chef-solo/cookbooks-2/mysql/libraries/helpers.rb:29:in
> `client_package_name'
>      /home/ec2-user/chef-
> solo/cookbooks-2/mysql/libraries/provider_mysql_client.rb:19:in `block in
> <class:MysqlClient>'
>  
>      Resource Declaration:
>      ---------------------
>      # In /home/ec2-user/chef-
> solo/cookbooks-2/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mysql.rb
>  
>       16:           mysql_client 'default' do
>       17:             version new_resource.client_version
>       18:             action :create
>       19:           end
>       20:
>  
>      Compiled Resource:
>      ------------------
>      # Declared in /home/ec2-user/chef-
> solo/cookbooks-2/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mysql.rb:16:in
> `block in <class:Mysql>'
>  
>      mysql_client("default") do
>        action [:create]
>        retries 0
>        retry_delay 2
>        guard_interpreter :default
>        cookbook_name :sample
>        version "5.5"
>      end
>  
[/code]

>
>
> ================================================================================  
>  Error executing action `install` on resource 'mysql2_chef_gem[default]'  
>
> ================================================================================
>
> NoMethodError
>
> * * *
>
> mysql_client[default] (/home/ec2-user/chef-
> solo/cookbooks-2/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mysql.rb
> line 16) had an error: NoMethodError: undefined method `[]' for nil:NilClass
>
> Cookbook Trace:
>
> * * *
>
> /home/ec2-user/chef-solo/cookbooks-2/mysql/libraries/helpers.rb:287:in
> `package_name_for'  
>  /home/ec2-user/chef-
> solo/cookbooks-2/mysql/libraries/helpers.rb:319:in`client_package'  
>  /home/ec2-user/chef-solo/cookbooks-2/mysql/libraries/helpers.rb:29:in
> `client_package_name'  
>  /home/ec2-user/chef-
> solo/cookbooks-2/mysql/libraries/provider_mysql_client.rb:19:in`block in '
>
> Resource Declaration:
>
> * * *
>
> # In /home/ec2-user/chef-solo/cookbooks-3/sample/recipes/default.rb
[code]

>      9: mysql2_chef_gem 'default' do
>     10:   client_version node['mysql']['version'] if node['mysql']
>     11:   action :install
>     12: end
>     13:
>  
[/code]

>
> Compiled Resource:
>
> * * *
>
> # Declared in /home/ec2-user/chef-
> solo/cookbooks-3/sample/recipes/default.rb:9:in `from_file'
>
> mysql2_chef_gem("default") do  
>  action [:install]  
>  retries 0  
>  retry_delay 2  
>  guard_interpreter :default  
>  cookbook_name :sample  
>  recipe_name "default"  
>  client_version "5.5"  
>  gem_version "0.3.17"  
>  end
>
> Running handlers:  
>  [2015-02-15T14:50:55+00:00] ERROR: Running exception handlers  
>  Running handlers complete  
>  [2015-02-15T14:50:55+00:00] ERROR: Exception handlers complete  
>  [2015-02-15T14:50:55+00:00] FATAL: Stacktrace dumped to
> /var/chef/cache/chef-stacktrace.out  
>  Chef Client failed. 0 resources updated in 3.096810316 seconds  
>  [2015-02-15T14:50:55+00:00] ERROR: mysql2_chef_gem[default]
> (sample::default line 9) had an error: NoMethodError: mysql_client[default]
> (/home/ec2-user/chef-
> solo/cookbooks-2/mysql2_chef_gem/libraries/provider_mysql2_chef_gem_mysql.rb
> line 16) had an error: NoMethodError: undefined method `[]' for nil:NilClass  
>  [2015-02-15T14:50:55+00:00] FATAL: Chef::Exceptions::ChildConvergeError:
> Chef run process exited unsuccessfully (exit code 1)


CC BY-SA 3.0
2015-02-15T08:51:18.160
6522
2016-11-02T11:35:37.750
2015-02-15T15:14:15.323
8294
8294
question
mysql chef aws
chef solo における database のエラー


下記の mysql.rb がなくなったのが原因かなと思われます。  
<https://github.com/opscode-cookbooks/database/blob/v3.1.0/recipes/mysql.rb>

sample/metadata.rb に、depends "mysql2_chef_gem" を付け加えて

sample/recipes/default.rb の最初に、mysql.rb と同じ内容の

mysql2_chef_gem 'default' do  
client_version node['mysql']['version'] if node['mysql']  
action :install  
end

をおいてみてください。


CC BY-SA 3.0
2015-02-15T12:15:05.203
6526
2015-02-15T12:15:05.203
5922
6522
answer