[chef] Re: Re: Variables in attributes file


Chronological Thread 
  • From: Alex < >
  • To: Chef Mailinglist < >
  • Subject: [chef] Re: Re: Variables in attributes file
  • Date: Wed, 4 Sep 2013 18:30:50 -0400

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.

§