Created
December 18, 2015 19:08
-
-
Save TechplexEngineer/f782432955722332e0ce to your computer and use it in GitHub Desktop.
Server automation using paramiko
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment