/
main.py
31 lines (26 loc) · 861 Bytes
/
main.py
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
28
29
30
31
from fabric import Connection
import getpass
import yaml
from helpers import print_color_text, print_log, print_table, run_commands
with open("hosts.yml") as file:
data = yaml.load(file, Loader=yaml.FullLoader)
hosts = data["hosts"]
print_table(hosts)
selected_host = None
while selected_host is None:
id_host = int(input("Selecciona el host: "))
if id_host < len(hosts):
selected_host = hosts[id_host]
else:
print("Host no valido")
password = getpass.getpass("Ingresa la contraseña: ")
try:
with Connection(
host=selected_host["host"],
user=selected_host["user"],
connect_kwargs={"password": password,},
) as c:
run_commands(c, selected_host)
print(print_color_text("Done!", 'green'))
except Exception as exception:
print(TRED + "Error de conexión: ", exception, ENDC)