[chef] Re: Variables in attributes file


Chronological Thread 
  • From: Carlton Stedman < >
  • To:
  • Subject: [chef] Re: Variables in attributes file
  • Date: Wed, 4 Sep 2013 11:31:03 -0400

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.

§