Unexpected hash's behavior

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?

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?

Thank you for the quick response.
I will follow your advice.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs