Need help using node ['default_gateway']


#1

i am trying write code to copy krb5.conf to the server only if the server have gateway (172.01.112.1) but here it seem node['default_gateway'] is not working.

cookbook_file '/etc/krb5.conf' do
only_if { node['default_gateway'] == '172.01.112.1' }
source 'krb5.conf'
backup 5
end

Please help me with it
thanks in advance


#2

That ohai attribute is nested under network, you need to use node['network']['default_gateway']

for example from your chef repo directory run

knife node show servername -a default_gateway

vs

knife node show servername -a network.default_gateway

Check out the examples under SHOW in the knife node docs
https://docs.chef.io/knife_node.html


#3

Thx! It worked

Your like god :wink:


#4

No problem, if you are all good I think you can mark this solved.


#5

Any idea , similarly how to get netmask value.


#6

it appears to be buried a bit
['network']['interfaces']['$interfacename']['addresses']['ipaddress']['netmask']

So it would need something like

['network']['interfaces']['eth0']['addresses']['192.168.1.10']['netmask']

Im not sure if this would work or not

['network']['interfaces']['node['network']['default_interface']']['addresses']['node['ipaddress']']['netmask']