How to set an attribute inside a cookbook?

Hi,

I want to set an attribute in another cookbook otherwise it will fail
during ‘kitchen converge’

   Chef::Exceptions::ValidationFailed
   ----------------------------------
   Required argument password is missing!

    23:
    24:  # Set password according to attribute, if set
    25:  mysqld_password 'root' do
    26>>   password node['mysqld']['root_password']

I have tried these

node[‘mysqld’][‘root_password’] = ‘password’

and

node.default[‘mysqld’][‘root_password’] = ‘password’

before this line

include_recipe “mysqld”

But apparently it has no effect.

What is the proper way to set a variable of a included cookbook?

On Mon, Feb 16, 2015 at 08:04:07AM +1100, Anthony Kong wrote:

I want to set an attribute in another cookbook otherwise it will fail
during 'kitchen converge'

   Chef::Exceptions::ValidationFailed
   ----------------------------------
   Required argument password is missing!

    23:
    24:  # Set password according to attribute, if set
    25:  mysqld_password 'root' do
    26>>   password node['mysqld']['root_password']

You should use node#default:

node.default['mysqld']['root_password'] = 'password'
include_recipe 'mysqld'

If that fails, make sure the mysql cookbook is not being included before
somewhere else.

--
Xabier de Zuazo

Try moving setting the attribute into an attribute file.

On 2/15/15 1:04 PM, Anthony Kong wrote:

Hi,

I want to set an attribute in another cookbook otherwise it will fail
during 'kitchen converge'

Chef::Exceptions::ValidationFailed

   Required argument password is missing!

    23:
    24:  # Set password according to attribute, if set
    25:  mysqld_password 'root' do
    26>>   password node['mysqld']['root_password']

I have tried these

node['mysqld']['root_password'] = 'password'

and

node.default['mysqld']['root_password'] = 'password'

before this line

include_recipe "mysqld"

But apparently it has no effect.

What is the proper way to set a variable of a included cookbook?