1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| from fabric import task from fabric import ThreadingGroup as Group
hosts = ['10.103.172.101', '10.103.172.102', '10.103.172.103', '10.103.172.104', '10.103.172.105', '10.103.172.106']
@task def exec(c, cmd, arg1=""): group = Group(*hosts, user='root', connect_kwargs={'password': 'Admin@123.perf'})
results = group.run(f'{cmd} {arg1}', hide=True)
for connection, result in results.items(): print(f'{connection.host}:\n{result.stdout}')
@task def put(c, script): group = Group(*hosts, user='root', connect_kwargs={'password': 'Admin@123.perf'})
for connection in group: remote_path = f"/tmp/{script.split('/')[-1]}" connection.put(script, remote_path)
|