2016-08-24 69 views
0

我在我的地方得到了一个数据中心类型的设置。所以基本上我创建它会使用过滤器参数,包括数据中心名称过滤ip的厨师

for eg:- 

10.21.53.x :- APP1 {10.21.53. belongs to APP1 datacenter and so on} 
10.92.252.x :- APP2 
10.23.252.x :- APP3 

I am trying to write an erb template where 
>>if the ip address matches "10.21.53.x" the variable should be set as APP1 
>>if the ip address matches "10.92.252.x" the variable should be set as APP2 
>>if the ip address matches "10.23.252.x" the variable should be set as APP3 
+0

因此可以说我有这样的事情: - a =“192.168.23.23” 我期待做的事: if a ==“192.168.23。?” {哪里?可以是任何东西} print“ert” – Ashwin

回答

0

我用采用分体式的概念,它似乎已经工作了logstash的conf文件。

>>> a 
'192.168.23.23' 
>>> a 
'192.168.23.23' 
>>> a.split() 
['192.168.23.23'] 
>>> a.split(".") 
['192', '168', '23', '23'] 
>>> a.split(".")[0] 
'192' 
>>> a.split(".")[1] 
'168' 
>>> if a.split(".")[1] == 168: 
... print "hey" 
... 
>>> if a.split(".")[1] == '168': 
... print "hey" 
... 
hey 

用于重新加入到IP

>>> ".".join(a.split(".")[:3]) 
'192.168.23' 

使用该代码在厨师壳写的所有三个八位字节比较,并相应地进行测试

节点[“网络”] [“接口” ] [“eth1”] [“addresses”]。select {| address,data |数据[“家庭”] ==“inet”} .keys.join.split(“。”)[0,3] .join(“。”)