[chef] Re: Re: Re: Variables in attributes file


Chronological Thread 
  • From: Carlton Stedman < >
  • To:
  • Subject: [chef] Re: Re: Re: Variables in attributes file
  • Date: Tue, 10 Sep 2013 08:03:18 -0400

The attributes files are just rb, so logic could be put in there.

However, as a best practice, I generally do little/no logic in the attributes files, treating them more as strict data. I would generate derived node attributes (using node.set/node.save as in above ruby_block) in recipes.

The reason for this is if I override an attribute in a wrapper cookbook, then I don't want to have to put the logic in the wrapper cookbook, just override an attribute and have the base (wrapped) cookbook do the logic using the overridden attribute.


On Wed, Sep 4, 2013 at 6:30 PM, Alex < " target="_blank"> > wrote:
Carlton,

It's ironic that you replied since I'm trying to generate these attributes to use with the dynect cookbook.

Is it possible to do it in the attributes file?


On Wed, Sep 4, 2013 at 11:31 AM, Carlton Stedman < " target="_blank"> > wrote:
Set up a ruby_block in a recipe with a node.set, like so:

ruby_block "do something" do
  block do
    bar, baz = # something
    node.set["foo"][bar] = baz
    node.save # only if chef-zero/chef-client
  end
end

That block can subscribe or be notified by other resources. Not sure if it works, at all, with chef solo, but give chef zero a try.

-Carlton


On Tue, Sep 3, 2013 at 10:50 PM, Alex < " target="_blank"> > wrote:

Is it possible to create attributes based on a dynamic variables?


# Example

default['ipdns']['#{int}']['address'] = '#{ip}'


# Code

node['network']["interfaces"].each do | int, parms |

  if int =~ /eth/

    File.open("/etc/sysconfig/network-scripts/ifcfg-#{int}") do |f|

      f.each_line do |line|

        if line.strip == ">

          node['network']["interfaces"]["#{int}"]["addresses"].each do |ip, params|

            if params['family'] == ('inet')

              #puts "#{int} - #{ip}"

              #puts "default['ipdns']['#{int}']['address'] = '#{ip}'"

              default['ipdns']['#{int}']['address'] = '#{ip}'

              #puts { "int" => "{int}", "ip" => "{ip}" }

            end

          end

        end

      end

    end

  end

end







Archive powered by MHonArc 2.6.16.

§