[chef] Re: Re: Re: Re: Re: node.run_state


Chronological Thread 
  • From: Matthew Moretti < >
  • To: " " < >
  • Subject: [chef] Re: Re: Re: Re: Re: node.run_state
  • Date: Mon, 22 Sep 2014 22:06:36 -0400

This sort of error pops up when you try to set an attribute deeper than is currently defined. That is if node.run_state['some'] or node.run_state['some']['dynamic'] or node.run_state['some']['dynamic']['attribute'] doesn’t exist (is nil) then you can’t set it’s sub-values.

Since this is a temporary state value, is there any reason to burry it so deep? Probably this would be sufficient:

ruby_block "set_attr_#{attr}" do
  block do
    node.run_state['a_temporary_value_of_some_kind''] = val
  end
end

Hope that helps.

Matt Moretti


On Mon, Sep 22, 2014 at 9:51 PM, DV < " target="_blank"> > wrote:
Maybe you guys can help me out really quick. I was very happy to have found out about node.run_state because we just happened to need to set some runtime attributes set dynamically thru a recipe.

But, the following code works, and the one below it doesn't.

    ruby_block "set_attr_#{attr}" do
            block do
                    eval ( "node.normal['some']['dynamic']['attribute']['name'] = #{val}" )
            end
    end

(attribute gets stored in node object, do not want this permanence)

versus:

    ruby_block "set_attr_#{attr}" do
            block do
                    eval ( "node.run_state['some']['dynamic']['attribute']['name'] = #{val}" )
            end
    end

(doesn't work, but do want).

The error we get for the 2nd block:

NoMethodError: ruby_block[set_attr_zenoss.enabled] (custom-resource::env_attributes line 24) had an error: NoMethodError: undefined method `[]=' for nil:NilClass

The reason we're putting this into ruby block is because "['some']['dynamic']['attribute']['name']" part needs to be changeable thru attribute (in effect, setting node['something']['or']['other'] = some_value for the duration of chef-client run).

Is there anything we can do about this? Is there anything else close to node.run_state that we can use?

On Wed, Sep 10, 2014 at 2:53 PM, James Scott < " target="_blank"> > wrote:
OK, so the release notes/breaking changes topic is updated:


and there's an example of using node.run_state here:


james

On Wed, Sep 10, 2014 at 10:51 AM, Julian C. Dunn < " target="_blank"> > wrote:
Yes, we (ChefCo) should probably pull the materials from the
intermediate class curriculum to illustrate the use of node.run_state.

+ James

- Julian

On Wed, Sep 10, 2014 at 10:46 AM, John Warren < " target="_blank"> > wrote:
> Thanks for the reply.  The apparent lack of documentation of node.run_state
> is a bit troubling: the link below is the first Google hit when I search for
> "chef node run_state".  Is there any documentation that discusses
> node.run_state in depth, the way node attributes are discussed, for instance
> here: https://docs.getchef.com/chef_overview_attributes.html ?  You have me
> convinced that node.run_state is kosher, but the people who review my code
> and have already -1'd it (citing the reference below) may not be as easily
> swayed.  Having official documentation that refutes the erroneous heading in
> the referenced official release notes would be most helpful in making my
> case that my code (at least as far as the use of node.run_state goes) is up
> to spec.
>
> Thanks,
>
> John
>
> -----Original Message----- From: Julian C. Dunn
> Sent: Wednesday, September 10, 2014 9:54 AM
> To: " target="_blank">
> Subject: [chef] Re: node.run_state
>
> I think the heading is just wrong. node.run_state is still used (and
> we teach it in Chef Intermediate :-) )
>
> - Julian
>
> On Wed, Sep 10, 2014 at 9:41 AM, John Warren < " target="_blank"> > wrote:
>>
>> The following section in the documentation for Chef client 11 appears to
>> be
>> a source of some confusion:
>>
>> https://docs.getchef.com/breaking_changes_chef_11.html#node-run-state-replaced
>> The heading of the section would seem to indicate that node.run_state
>> should
>> not be used at all anymore, while the section text seems to reference only
>> node.run_state[:seen_recipes] as no longer being valid.  Can I get some
>> clarification on what the status of node.run_state is in terms of having
>> been “replaced” as a whole or in part?
>>
>> Thanks,
>>
>> John
>
>
>
>
> --
> [ Julian C. Dunn < " target="_blank"> >          * Sorry, I'm    ]
> [ WWW: http://www.aquezada.com/staff/julian    * only Web 1.0  ]
> [ gopher://sdf.org/1/users/keymaker/           * compliant!    ]
> [ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9       ]



--
[ Julian C. Dunn < " target="_blank"> >          * Sorry, I'm    ]
[ WWW: http://www.aquezada.com/staff/julian    * only Web 1.0  ]
[ gopher://sdf.org/1/users/keymaker/           * compliant!    ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9       ]




--
Best regards, Dmitriy V.




Archive powered by MHonArc 2.6.16.

§