Chef-solo and override attributes will not work in json role


#1

Do override attributes work in chef-solo?

Here is my role:

{
“name”: “server”,
“chef_type”: “role”,
“description”: “server”,
“override_attributes”: {“environment”:{“git_repos”:[“logic”]}},
“run_list”:
[“recipe[build-essential]”,“recipe[java]”,“recipe[environment::scm]” ]
}

In my cookbook called “environment”…in attributes have this this:

#cookbooks/'environment/attributes/default.rb
default[‘environment’][‘git_repos’] = []

In my scm recipe “recipe[environment::scm]” I have this for a test:

git_repos = node[‘environment’][‘git_repos’]
git_repos.each do |repo|

directory “/home/ubuntu/wtf/” do
owner "root"
group “root”
#mode "0775"
recursive true
action :create
end

end

Nothing…no errors …no nothing. So…do overide attributes work? Is
so…then why not working for me?

Thanks


#2

On Thursday, January 16, 2014 at 12:28 AM, David Montgomery wrote:

Do override attributes work in chef-solo?

Here is my role:

{
“name”: “server”,
“chef_type”: “role”,
“description”: “server”,
“override_attributes”: {“environment”:{“git_repos”:[“logic”]}},
“run_list”: [“recipe[build-essential]”,“recipe[java]”,“recipe[environment::scm]” ]
}

In my cookbook called “environment”…in attributes have this this:

#cookbooks/'environment/attributes/default.rb
default[‘environment’][‘git_repos’] = []

In my scm recipe “recipe[environment::scm]” I have this for a test:

git_repos = node[‘environment’][‘git_repos’]
git_repos.each do |repo|

directory “/home/ubuntu/wtf/” do
owner "root"
group “root”
#mode "0775"
recursive true
action :create
end

end

Nothing…no errors …no nothing. So…do overide attributes work? Is so…then why not working for me?

Thanks

Override attributes are only set by cookbooks, roles, or environments. Attributes from the json file are always “normal” level, which is similar to how they work in chef-client.


Daniel DeLeo


#3

Then what do I do? default_attributes? will that work?

Kinda confused…why is the below in the docs?

http://docs.opscode.com/chef_solo.html

{
“name”: “test”,
“default_attributes”: { },
“override_attributes”: { },
“json_class”: “Chef::Role”,
“description”: “This is just a test role, no big deal.”,
“chef_type”: “role”,
“run_list”: [ “recipe[test]” ]}

On Fri, Jan 17, 2014 at 1:18 AM, Daniel DeLeo dan@kallistec.com wrote:

On Thursday, January 16, 2014 at 12:28 AM, David Montgomery wrote:

Do override attributes work in chef-solo?

Here is my role:

{
“name”: “server”,
“chef_type”: “role”,
“description”: “server”,
“override_attributes”: {“environment”:{“git_repos”:[“logic”]}},
“run_list”:
[“recipe[build-essential]”,“recipe[java]”,“recipe[environment::scm]” ]
}

In my cookbook called “environment”…in attributes have this this:

#cookbooks/'environment/attributes/default.rb
default[‘environment’][‘git_repos’] = []

In my scm recipe “recipe[environment::scm]” I have this for a test:

git_repos = node[‘environment’][‘git_repos’]
git_repos.each do |repo|

directory “/home/ubuntu/wtf/” do
owner "root"
group “root”
#mode "0775"
recursive true
action :create
end

end

Nothing…no errors …no nothing. So…do overide attributes work? Is
so…then why not working for me?

Thanks

Override attributes are only set by cookbooks, roles, or environments.
Attributes from the json file are always “normal” level, which is similar
to how they work in chef-client.


Daniel DeLeo


#4

On Thursday, January 16, 2014 at 1:30 PM, David Montgomery wrote:

Then what do I do? default_attributes? will that work?

Kinda confused…why is the below in the docs?

http://docs.opscode.com/chef_solo.html

{ “name”: “test”, “default_attributes”: { }, “override_attributes”: { }, “json_class”: “Chef::Role”, “description”: “This is just a test role, no big deal.”, “chef_type”: “role”, “run_list”: [ “recipe[test]” ] }

Sorry, I misread your original post, I thought you were trying to pass something like that in using -j JSON_FILE, which doesn’t work.

As far as I can tell from what you’ve posted, your example should work as long as your role is getting picked up in the run_list. You could try adding code like this to debug your attributes:

require 'pp’
pp node.debug_value(“environment")

You can also try running chef with debug logging to see if anything else looks odd.


Daniel DeLeo


#5

Him,

Still kinda stunned that chef will not work…now rather concerned and have
to hardcode to get around this till resolved. What am I missing from the
docs? How else can I create a role based execution patten in light
override_attributes are not working?

Opscode…any comment?

[[“set_unless_enabled?”, false],
[“default”, {“git_repos”=>[]}],
[“env_default”, :not_present],
[“role_default”, :not_present],
[“force_default”, :not_present],
[“normal”, :not_present],
[“override”, :not_present],
[“role_override”, :not_present],
[“env_override”, :not_present],
[“force_override”, :not_present],
[“automatic”, :not_present]]
Converging 4 resources
Recipe: environment::scm

  • package[git-core] action install (up to date)
  • file[/root/.ssh/id_rsa] action create (up to date)
  • cookbook_file[/root/.ssh/id_rsa] action create (up to date)
  • directory[/home/ubuntu/workspace/] action create (up to date)

here is my role:

{
“name”: “orderbook_server”,
“chef_type”: “role”,
“description”: “orderbook server”,
“override_attributes”: {“environment”:{“git_repos”:[“logic”]}},
“run_list”: [
“recipe[environment::scm]”

            ]

}

In the recipe…the code I am trying to execute

git_repos = node[“environment”][“git_repos”]
git_repos.each do |repo|
//do stuff
end

On Fri, Jan 17, 2014 at 6:18 AM, Daniel DeLeo dan@kallistec.com wrote:

On Thursday, January 16, 2014 at 1:30 PM, David Montgomery wrote:

Then what do I do? default_attributes? will that work?

Kinda confused…why is the below in the docs?

http://docs.opscode.com/chef_solo.html

{
“name”: “test”,
“default_attributes”: { },
“override_attributes”: { },
“json_class”: “Chef::Role”,
“description”: “This is just a test role, no big deal.”,
“chef_type”: “role”,
“run_list”: [ “recipe[test]” ]}

Sorry, I misread your original post, I thought you were trying to pass
something like that in using -j JSON_FILE, which doesn’t work.

As far as I can tell from what you’ve posted, your example should work as
long as your role is getting picked up in the run_list. You could try
adding code like this to debug your attributes:

require 'pp’
pp node.debug_value(“environment")

You can also try running chef with debug logging to see if anything else
looks odd.


Daniel DeLeo


#6

On Friday, January 17, 2014 at 12:30 AM, David Montgomery wrote:

Him,

Still kinda stunned that chef will not work…now rather concerned and have to hardcode to get around this till resolved. What am I missing from the docs? How else can I create a role based execution patten in light override_attributes are not working?

Opscode…any comment?

[[“set_unless_enabled?”, false],
[“default”, {“git_repos”=>[]}],
[“env_default”, :not_present],
[“role_default”, :not_present],
[“force_default”, :not_present],
[“normal”, :not_present],
[“override”, :not_present],
[“role_override”, :not_present],
[“env_override”, :not_present],
[“force_override”, :not_present],
[“automatic”, :not_present]]
Converging 4 resources
Recipe: environment::scm

  • package[git-core] action install (up to date)
  • file[/root/.ssh/id_rsa] action create (up to date)
  • cookbook_file[/root/.ssh/id_rsa] action create (up to date)
  • directory[/home/ubuntu/workspace/] action create (up to date)

here is my role:

{
“name”: “orderbook_server”,
“chef_type”: “role”,
“description”: “orderbook server”,
“override_attributes”: {“environment”:{“git_repos”:[“logic”]}},
“run_list”: [
“recipe[environment::scm]”

            ]

}

In the recipe…the code I am trying to execute

git_repos = node[“environment”][“git_repos”]
git_repos.each do |repo|
//do stuff
end

What does the logging output say your run_list and expanded run_list are? Are you 100% sure that the role is getting applied?

I’ve tested your role’s syntax with:

ruby -rubygems -rchef -rchef/role -e 'p Chef::JSONCompat.from_json(IO.read(“ex-role.json”))’

And I get:

{“name”=>“orderbook_server”, “chef_type”=>“role”, “description”=>“orderbook server”, “override_attributes”=>{“environment”=>{“git_repos”=>[“logic”]}}, “run_list”=>[“recipe[environment::scm]”]}

So your syntax is fine and the override attributes seem to be getting picked up.


Daniel DeLeo