2016-08-24 7 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 == "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' 

の全ての3つのオクテットを比較するために再び参加] ["eth1"] ["addresses"]。select {| address、data |データ["family"] == "inet"} .keys.join.split( "。")[0,3] .join( "。")

関連する問題