-
Notifications
You must be signed in to change notification settings - Fork 20
/
configer.py
60 lines (58 loc) · 1.66 KB
/
configer.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from pypinger import pyping
import yaml
def config_gen():
config = {
'inventory': {
'plugin': 'SimpleInventory',
'options': {
'host_file': 'inventory.yaml',
'group_file': 'groups.yaml'
}
},
'runner': {
'plugin': 'threaded',
'options': {
'num_workers': 1
}
}
}
f = open('config.yaml', 'w')
yaml.dump(config, f, allow_unicode=True)
hosts = pyping()
user = input("Username (default to cisco): ")
if not user:
user = 'cisco'
password = input("Passowrd (default to cisco): ")
if not password:
password = 'cisco'
hosts_list = {}
for host in hosts:
host_data = {
'hostname': host,
'username': user,
'password': password,
'groups': ['cisco_group']
}
hosts_list[host] = host_data
print(yaml.dump(hosts_list))
f = open('inventory.yaml', 'w')
yaml.dump(hosts_list, f, allow_unicode=True)
group = {
'cisco_group': {
'username': 'cisco',
'password': 'cisco',
'connection_options': {
'scrapli': {
'platform': 'cisco_iosxe',
'port': 22,
'extras': {'ssh_config_file': True, 'auth_strict_key': False}
},
'scrapli_netconf': {
'port': 830,
'extras': {'ssh_config_file': True, 'auth_strict_key': False}
}
}
}
}
f = open('groups.yaml', 'w')
yaml.dump(group, f, allow_unicode=True)