2016-08-24 67 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(「。」)