-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·122 lines (103 loc) · 4.24 KB
/
configure
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
#!/usr/bin/env python
import ConfigParser
def write_file(filename, to_write):
with open(filename, 'w') as dest:
dest.write(to_write)
def write_global_settings(settings_dict, ansible_settings):
if 'GLOBAL_SETTINGS_DEST' not in ansible_settings:
print "No GLOBAL_SETTINGS_DEST set in ANSIBLE variables"
return
dest_file = ansible_settings['GLOBAL_SETTINGS_DEST']
to_write = ""
for setting in settings_dict:
to_write += "%s: \"%s\"\n" % (str.upper(setting), settings_dict[setting])
write_file(dest_file, to_write)
def write_badgekit_api_env_settings(settings_dict, ansible_settings):
if 'API_ENV_FILE_DEST' not in ansible_settings:
print "No API_ENV_FILE_DEST set in ANSIBLE variables"
return
dest_file = ansible_settings['API_ENV_FILE_DEST']
to_write = ""
for setting in settings_dict:
to_write += "%s: %s\n" % (str.upper(setting), settings_dict[setting])
write_file(dest_file, to_write)
def write_badgekit_api_install_settings(settings_dict, ansible_settings):
if 'API_INSTALL_DEST' not in ansible_settings:
print "No API_INSTALL_DEST set in ANSIBLE variables"
return
dest_file = ansible_settings['API_INSTALL_DEST']
to_write = ""
for setting in settings_dict:
to_write += "%s: %s\n" % (str.upper(setting), settings_dict[setting])
write_file(dest_file, to_write)
def write_badgekit_admin_env_settings(settings_dict, ansible_settings):
if 'ADMIN_ENV_FILE_DEST' not in ansible_settings:
print "No ADMIN_ENV_FILE_DEST set in ANSIBLE variables"
return
dest_file = ansible_settings['ADMIN_ENV_FILE_DEST']
to_write = ""
for setting in settings_dict:
to_write += "%s: %s\n" % (str.upper(setting), settings_dict[setting])
write_file(dest_file, to_write)
def write_badgekit_admin_install_settings(settings_dict, ansible_settings):
if 'ADMIN_INSTALL_DEST' not in ansible_settings:
print "No ADMIN_INSTALL_DEST set in ANSIBLE variables"
return
dest_file = ansible_settings['ADMIN_INSTALL_DEST']
to_write = ""
for setting in settings_dict:
to_write += "%s: \"%s\"\n" % (str.upper(setting), settings_dict[setting])
write_file(dest_file, to_write)
def write_local_mysql_settings(settings_dict, ansible_settings):
if 'MYSQL_SETTINGS_DEST' not in ansible_settings:
print "No MYSQL_SETTINGS_DEST set in ANSIBLE variables"
return
dest_file = ansible_settings['MYSQL_SETTINGS_DEST']
to_write = ""
for setting in settings_dict:
to_write += "%s: \"%s\"\n" % (str.upper(setting), settings_dict[setting])
write_file(dest_file, to_write)
def main():
variables_filename = 'variables.ini'
with open(variables_filename) as variables_file:
parser = ConfigParser.ConfigParser()
parser.readfp(variables_file)
variables = {}
for section in parser.sections():
variables[section] = {}
for option, value in parser.items(section):
variables[section][option] = value
if 'ANSIBLE' not in variables:
print "Ansible variables not set in variables file: %s" % variables_filename
exit(1)
# Get all caps keys
ansible_vars = {}
for setting in variables['ANSIBLE']:
ansible_vars[str.upper(setting)] = variables['ANSIBLE'][setting]
if 'BADGEKIT API INSTALL' in variables:
write_badgekit_api_install_settings(variables['BADGEKIT API INSTALL'], ansible_vars)
else:
print "***WARNING: BADGEKIT API INSTALL NOT DEFINED IN VARIABLES FILE***"
if 'GLOBAL' in variables:
write_global_settings(variables['GLOBAL'], ansible_vars)
else:
print "***WARNING: GLOBAL SETTINGS NOT DEFINED IN VARIABLES FILE***"
if 'BADGEKIT ADMIN INSTALL' in variables:
write_badgekit_admin_install_settings(variables['BADGEKIT ADMIN INSTALL'], ansible_vars)
else:
print "***WARNING: BADGEKIT ADMIN INSTALL NOT DEFINED IN VARIABLES FILE***"
if 'BADGEKIT API VARIABLES' in variables:
write_badgekit_api_env_settings(variables['BADGEKIT API VARIABLES'], ansible_vars)
else:
print "***WARNING: BADGEKIT ADMIN VARIABLES NOT DEFINED IN VARIABLES FILE***"
if 'BADGEKIT ADMIN VARIABLES' in variables:
write_badgekit_admin_env_settings(variables['BADGEKIT ADMIN VARIABLES'], ansible_vars)
else:
print "***WARNING: BADGEKIT ADMIN VARIABLES NOT DEFINED IN VARIABLES FILE***"
if 'MYSQL' in variables:
write_local_mysql_settings(variables['MYSQL'], ansible_vars)
else:
print "***WARNING: MYSQL NOT DEFINED IN VARIABLES FILE***"
print "Done!"
if __name__ == "__main__":
main()