0
我需要檢查大量的服務器,如果他們安裝了廚師(別問)我試圖自動化它,而不是手動做。我以前從未使用python,我無法真正測試這個,直到我明天去,所以如果我在正確的軌道上尋找一些反饋。我想我把所有的IP地址轉儲到一個文本文件,通過它循環並保存需要安裝廚師的人員。通過SSH連接服務器,檢查是否安裝了廚師,並記錄它沒有安裝的服務器
import pxssh
import getpass
CheckIT = str("command not found")
for line in open('ServerList.txt','r').readlines():
try:
s = pxssh.pxssh()
hostname = raw_input('line ')
username = raw_input('username ')
password = getpass.getpass('password: ')
s.login (hostname, username, password)
s.sendline ('sudo su -') # run a command
s.prompt() # match the prompt
s.sendline ('chef-client')
s.prompt()
if CheckIT == readline(self,size=-1)
with open("ServersToUpdate.txt", "a") as myfile:
myfile.write(hostname)
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
如果沒有進一步措施,單獨檢查「如果廚師已安裝」本身並沒有什麼意義。您想要如何處理已安裝或未安裝Chef的節點? –
如果沒有安裝,那麼我需要安裝它,如果安裝沒有進一步的行動。 – InsertNameHere
爲什麼不直接引導每個節點? –