Override attributes using JSON

Hi,

I’m using Chef 0.9.6 on CentOS 5.5 - everything installed from Yum
repositories.

I need to create a user in the system, and then access this username in several
cookbooks. I have created a cookbook “create_user” that has this receipe:

user_name = node[:user_name]

username user_name do
… create actions here
end

And I have created an attribute for this cookbook:
default[:user_name]=“testuser”

So, if there is no username supplied, “testuser” is used.

Also, I’m creating a JSON file { “user_name”: “myuser” }

When I run “chef-client -j .json” on a non-registered node/client -
user “testuser” is created. Running the same command second time - node is
already registered from first run - user “myuser” is created.

If I run the same cookbook using chef-solo - everything works fine - only
"myuser" is created.

Why on first run of chef-client attributes are not overridden? How is possible
to achieve correct user creation on first chef-client run?

Thanks

Actually, this behavior is a bug that is fixed in the
soon-to-be-released Chef 0.9.8:

http://tickets.opscode.com/browse/CHEF-1387

You may be able to install the RC of Chef 0.9.8 with gem install chef --pre but I don't know how that works with the RPMs. The release
version will be identical to the RC except with some inline
documentation fixes.

Dan DeLeo

On Mon, Jul 26, 2010 at 12:13 PM, Vladimir Girnet
vgirnet@tacitknowledge.com wrote:

Hi,

I'm using Chef 0.9.6 on CentOS 5.5 - everything installed from Yum
repositories.

I need to create a user in the system, and then access this username in several
cookbooks. I have created a cookbook "create_user" that has this receipe:

user_name = node[:user_name]

username user_name do
... create actions here
end

And I have created an attribute for this cookbook:
default[:user_name]="testuser"

So, if there is no username supplied, "testuser" is used.

Also, I'm creating a JSON file { "user_name": "myuser" }

When I run "chef-client -j .json" on a non-registered node/client -
user "testuser" is created. Running the same command second time - node is
already registered from first run - user "myuser" is created.

If I run the same cookbook using chef-solo - everything works fine - only
"myuser" is created.

Why on first run of chef-client attributes are not overridden? How is possible
to achieve correct user creation on first chef-client run?

Thanks