Forum: Ruby Unexpected hash's behavior

D4689e6c2a52960e47bd8ea8f7804cec?d=identicon&s=25 Andrew Eliseykin (abelt2003)
on 2013-03-25 14:29
Hi all.
I'm newbie.
Help me, please.
I write Puppet function
Piece of code :


        n_if={}
         over_if = arguments[1]

  over_if.each do |kk,vv|
          weth={}
      puts kk,vv,weth
      weth = arguments[0]
      weth['in_vlan'] = vv['in_vlan']
      weth['options']['MTU'] = vv['mtu']
      n_if['eth'+ kk.to_s]=weth
  end

Data readed from 2 files, and passed into arguments[0] and arguments[1]
respectively:

# template of ethernet interfaces
eth_:
  method: "static"
  family: "inet"
  ip: ""
  netmask: "255.255.0.0"
  onboot:  true
  options:
    MTU: ""
  in_vlan: ""

# values for include into ethernet interfaces
eth_values:
 0:
  mtu: 1500
  in_vlan: 15
 1:
  mtu: 9000
  in_vlan: 125


I expect get hash with keys 'eth0' and 'eth1' as follow:
eth1methodstaticfamilyinetin_vlan125ipnetmask255.255.0.0onboottrueoptionsMTU9000eth0methodstaticfamilyinetin_vlan15ipnetmask255.255.0.0onboottrueoptionsMTU1500
But I get :
eth1methodstaticfamilyinetin_vlan125ipnetmask255.255.0.0onboottrueoptionsMTU9000eth0methodstaticfamilyinetin_vlan125ipnetmask255.255.0.0onboottrueoptionsMTU9000

What is my mistake?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2013-03-25 14:33
It sounds like you're not incrementing whatever number you're using
between writing eth0 and eth1

Have you tried doing this step by step in IRB or adding debugging
outputs to check the results after each step?
D4689e6c2a52960e47bd8ea8f7804cec?d=identicon&s=25 Andrew Eliseykin (abelt2003)
on 2013-03-25 15:32
Thank you for the quick response.
I will follow your advice.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.