Server automation using paramiko
import paramiko, time
def run_commands(ip_address, user, password, commandList, buff=5000):
print "Configuring " + ip_address
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip_address, username=user, password=password)
chan = client.invoke_shell()
if not isinstance(commandList, list):
commandList = commandList.split('\n')
for com in commandList:
chan.send(com+'\n')
time.sleep(1)
output = chan.recv(buff)
print output
print
if __name__ == '__main__':
# run_commands('50.1.1.1', 'vyos', 'vyos', ['echo $PATH'])
cmds = ['echo $PATH']
user = 'vyos'
passwd = 'vyos'
hosts = ['50.1.1.1','50.1.1.2']
for h in hosts:
run_commands(h, user, passwd, cmds)