【发布时间】:2017-11-23 17:00:08
【问题描述】:
如果他们安装了厨师,我需要检查很多服务器(不要问)我试图自动化它而不是手动执行它。我以前从未使用过python,直到明天我才能真正测试它,所以如果我在正确的轨道上,我正在寻找一些反馈。我想我将所有IP地址转储到一个文本文件中,循环遍历它并保存需要安装 chef 的那些。
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”并没有真正意义。您想对已安装或未安装 Chef 的节点做什么?
-
如果没有安装那么我需要安装它,如果安装了没有进一步的操作。
-
为什么不直接引导每个节点?
标签: python ssh chef-infra pxssh