-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory.py
executable file
·318 lines (270 loc) · 13.8 KB
/
inventory.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/usr/bin/env python
import argparse
import os
import sys
try:
import json
except ImportError:
import simplejson as json
class Inventory(object):
############################################################################
################# DON'T CHANGE THIS ########################################
############################################################################
def __init__(self):
self.inventory = {}
self.read_cli_args()
if self.args.list:
self.inventory = self.inventory_generator()
elif self.args.host:
# Not implemented, since we return _meta info `--list`.
self.inventory = self.empty_inventory()
else:
self.inventory = self.empty_inventory()
print(json.dumps(self.inventory))
with open("temp", 'w') as f:
f.write(json.dumps(self.inventory))
############################################################################
################# DON'T CHANGE THIS ########################################
############################################################################
def inventory_generator(self):
inventory = {}
_meta = {}
hostvars = {}
#####################################################################################################
all = {}
all_vars = {}
all_vars['prefered_DNS'] = '8.8.8.8'
all_vars['vcenter_hostname'] = 'cdr-vcenter.cse.buffalo.edu'
all_vars['datastore'] = 'cdr-backup'
all_vars['datacenter'] = 'UBNetDef'
all_vars['cluster'] = 'MAIN'
all_vars['parent_folder'] = 'Competition'
all_vars['WAN_start_address'] = '192.168.253.2'
all_vars['pfsense_dns'] = all_vars['prefered_DNS']
all_vars['Upstream_gateway_start_address'] = '192.168.253.1'
all_vars['start_team'] = 1
#todo Change number of teams
all_vars['total_teams'] = 13
all_vars['Lockdown_user_role'] = 'Lockdown blue team'
all_vars['afinity_enable'] = True
all_vars['pfsense_template'] = 'Router-v8'
all_vars['cloud_folder'] = '{}_Cloud'.format(all_vars['parent_folder'])
all_vars['domain'] = 'ticket.lockdown'
all_vars['netbios'] = 'TICKETS'
all_vars['WAN_Subnet'] = 29
all_vars['IP_jump'] = 8
all['vars'] = all_vars
#####################################################################################################
#####################################################################################################
# LAN
Ubuntu1 = ['10.X.1.10'.replace('X', str(i))for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
Ubuntu2 = ['10.X.1.40'.replace('X', str(i))for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
Ubuntu3 = ['10.X.1.90'.replace('X', str(i))for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
CentOS = ['10.X.1.30'.replace('X', str(i))for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
Active_Directory = ['10.X.1.60'.replace('X', str(i))for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
Windows1 = ['10.X.1.70'.replace('X', str(i))for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
Windows2 = ['10.X.1.80'.replace('X', str(i))for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
# DMZ
WEB = ['10.X.2.2'.replace('X', str(i)) for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
DB = ['10.X.2.3'.replace('X', str(i)) for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
FTP = ['10.X.2.4'.replace('X', str(i)) for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
DevServer = ['10.X.2.10'.replace('X', str(i))for i in range(
all_vars['start_team'], all_vars['total_teams'] + all_vars['start_team'])]
cloud = FTP + DB + WEB + DevServer
for host_list in [
Ubuntu1, Ubuntu2, Ubuntu3, CentOS, Active_Directory, Windows1, Windows2, WEB, DB, FTP, DevServer
]:
for idx, host in enumerate(host_list):
team_number = idx + all_vars['start_team']
hostvars[host] = {}
hostvars[host]['customization'] = {}
hostvars[host]['timeout'] = 300
network = {}
#FIX THE AD DEPLOYMENT ROLES
if host in Active_Directory:
hostvars[host]['domain_name'] = all_vars['domain']
hostvars[host]['netbios_name'] = all_vars['netbios']
hostvars[host]['ad_backuppass'] = 'Change.me!'
hostvars[host]['template'] = "v13-ADDS-Windows"
#hostvars[host]['template'] = "AD-Sucks"
hostvars[host]['AD_Name'] = 'AD'
#if host in AliExpressWindows: #Formally RogueLinux, but now updated.
# #hostvars[host]['template'] = 'Desktop-Ubuntu-Rouge-18.04-v8'
# hostvars[host]['template'] = 'Knockoff95-v12'
# hostvars[host]['AD_Name'] = 'WeirdWindows'
if host in Ubuntu1:
hostvars[host]['template'] = 'v13-UbuntuX'
hostvars[host]['AD_Name'] = 'Ubuntu1'
if host in Ubuntu2:
hostvars[host]['template'] = 'v13-UbuntuX'
hostvars[host]['AD_Name'] = 'Ubuntu2'
if host in Ubuntu3:
hostvars[host]['template'] = 'v13-UbuntuX'
hostvars[host]['AD_Name'] = 'Ubuntu3'
#VASU PLEASE UPDATE THE DAMN CENTOS VM
if host in CentOS:
hostvars[host]['template'] = 'v13-WebApp'
hostvars[host]['AD_Name'] = 'Winux'
if host in Windows1:
hostvars[host]['template'] = 'v13-WindowsX'
hostvars[host]['AD_Name'] = 'Windows1'
if host in Windows2:
hostvars[host]['template'] = 'v13-WindowsX'
hostvars[host]['AD_Name'] = 'Windows2'
if host in FTP:
hostvars[host]['template'] = 'v13-Linux-FTP'
hostvars[host]['AD_Name'] = 'FTP'
if host in DevServer:
hostvars[host]['template'] = 'v13-DevServer'
hostvars[host]['AD_Name'] = 'DevServer'
if host in WEB:
hostvars[host]['template'] = 'v13-Backup'
hostvars[host]['AD_Name'] = 'WEB'
hostvars[host]['apache_mods_enabled'] = ['rewrite.load']
if host in DB:
hostvars[host]['template'] = 'v13-UbuntuServer'
hostvars[host]['AD_Name'] = 'DATABASE'
hostvars[host]['mysql_users'] = []
hostvars[host]['mysql_users'].append({
'name': 'badmin',
'host': '%',
'password': 'changeme',
'priv': '*.*:ALL,GRANT'
})
hostvars[host]['mysql_users'].append({
'name': 'scam',
'host': '%',
'password': 'changeme',
'priv': '*.*:ALL,GRANT'
})
hostvars[host]['mysql_users'].append({
'name': 'magic',
'host': '%',
'password': 'changeme',
'priv': '*.*:ALL,GRANT'
})
hostvars[host]['mysql_users'].append({
'name': 'admin',
'host': '%',
'password': 'changeme',
'priv': '*.*:ALL,GRANT'
})
hostvars[host]['mysql_databases'] = []
hostvars[host]['mysql_databases'].append({
'name': 'data',
'collation': 'utf8_general_ci',
'encoding': 'utf8',
'replicate': 0
})
if host in Active_Directory:
hostvars[host]['ansible_user'] = 'Administrator'
hostvars[host]['ansible_password'] = 'Change.me!'
hostvars[host]['customization']['password'] = hostvars[host]['ansible_password']
hostvars[host]['timeout'] = 600
if host in Windows1 + Windows2:
hostvars[host]['ansible_user'] = 'Admin'
hostvars[host]['ansible_password'] = 'Change.me!'
hostvars[host]['timeout'] = 600
#DEFINE LINUX VMS HERE
if host in Ubuntu1 + Ubuntu2 + Ubuntu3 + WEB + DB + DevServer + CentOS + FTP:
hostvars[host]['ansible_user'] = 'sysadmin'
hostvars[host]['ansible_password'] = 'changeme'
hostvars[host]['ansible_become_pass'] = hostvars[host]['ansible_password']
hostvars[host]['OS'] = 'Linux'
if host in Windows1 + Windows2:
hostvars[host]['dns_domain_name'] = hostvars[
Active_Directory[idx]]['domain_name']
hostvars[host]['domain_admin_password'] = hostvars[
Active_Directory[idx]]['ansible_password']
hostvars[host]['domain_admin_user'] = hostvars[
Active_Directory[idx]]['ansible_user']
#DEFINE WINDOWS VMS HERE
if host in Active_Directory + Windows1 + Windows2:
hostvars[host]['ansible_connection'] = 'winrm'
hostvars[host]['ansible_winrm_server_cert_validation'] = 'ignore'
hostvars[host]['OS'] = 'Windows'
if host not in Active_Directory:
hostvars[host]['customization']['dns_servers'] = [Active_Directory[idx], all_vars['prefered_DNS']]
network['dns_servers'] = [Active_Directory[idx], all_vars['prefered_DNS']]
else:
hostvars[host]['customization']['dns_servers'] = [all_vars['prefered_DNS']]
network['dns_servers'] = [all_vars['prefered_DNS']]
if host in cloud:
hostvars[host]['folder'] = 'Lockdown/{}/{}'.format(
all_vars['parent_folder'], all_vars['cloud_folder'])
else:
hostvars[host]['folder'] = 'Lockdown/{}/Team{:02d}'.format(
all_vars['parent_folder'], team_number)
def networking (ip):
network['name'] = "team{}-net".format(team_number)
network['ip'] = ip
network['netmask'] = '255.255.255.0'
network['gateway'] = "10.{}.{}.1".format(team_number, host.split('.')[2])
network['start_connected'] = True
return network
hostvars[host]['networks'] = [networking(host)]
hostvars[host]['team_number'] = team_number
hostvars[host]['customization']['hostname'] = hostvars[host]['AD_Name']
Active_Directory_dict = {}
Windows1_dict = {}
Windows2_dict = {}
#AliExpressWindows_dict = {}
Ubuntu1_dict = {}
Ubuntu2_dict = {}
Ubuntu3_dict = {}
CentOS_dict = {}
FTP_dict = {}
WEB_dict = {}
DB_dict = {}
DevServer_dict = {}
Active_Directory_dict["hosts"] = Active_Directory
Windows1_dict["hosts"] = Windows1
Windows2_dict["hosts"] = Windows2
#AliExpressWindows_dict["hosts"] = AliExpressWindows
Ubuntu1_dict["hosts"] = Ubuntu1
Ubuntu2_dict["hosts"] = Ubuntu2
Ubuntu3_dict["hosts"] = Ubuntu3
CentOS_dict["hosts"] = CentOS
FTP_dict["hosts"] = FTP
WEB_dict["hosts"] = WEB
DB_dict["hosts"] = DB
DevServer_dict['hosts'] = DevServer
#TODO: Potentially include palo Alto
################################################################################################
#Comment/Uncomment here to include/exclude from deployment. Limit removal from top. Recall "Chesterton's Fence"
inventory['all'] = all
inventory['Active_Directory'] = Active_Directory_dict
inventory['Windows1'] = Windows1_dict
inventory['Windows2'] = Windows2_dict
inventory['Ubuntu1'] = Ubuntu1_dict
inventory['Ubuntu2'] = Ubuntu2_dict
#inventory['Ubuntu3'] = Ubuntu3_dict
inventory['WebApp'] = CentOS_dict
inventory['UbuntuFTP'] = FTP_dict
inventory['BackupServer'] = WEB_dict
#inventory['DB'] = DB_dict
inventory['MailServer'] = DevServer_dict
#################################################################################################
_meta['hostvars'] = hostvars
inventory['_meta'] = _meta
return inventory
# Empty inventory for testing.
def empty_inventory(self):
return {'_meta': {'hostvars': {}}}
# Read the command line args passed to the script.
def read_cli_args(self):
parser = argparse.ArgumentParser()
parser.add_argument('--list', action='store_true')
parser.add_argument('--host', action='store')
self.args = parser.parse_args()
Inventory()