-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathit-create-environment.rb
More file actions
executable file
·95 lines (72 loc) · 2.24 KB
/
it-create-environment.rb
File metadata and controls
executable file
·95 lines (72 loc) · 2.24 KB
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
#!/usr/bin/ruby
require "highline/import"
require 'yaml'
require 'git'
require 'logger'
def create_a_branch(branch, path)
g = Git.open(path, :log => Logger.new(STDOUT))
g.branch(branch).checkout
g.push("origin", branch)
end
env = ask("What is the name of the new environment?") do |q|
q.validate = /.+/
q.responses[:not_valid] = "Should not be blank"
end
#
env.downcase!
email = ask("What is your email to send notifications?") do |q|
q.default = "luis.oscar.pigueiras.areces@cern.ch"
end
if ask("Do you want to override a module?") { |q| q.default = "Y" } == "Y"
mod = ask("What is the name of the module?") do |q|
q.validate = /.+/
q.responses[:not_valid] = "Should not be blank"
end
end
if ask("Do you want to override a hostgroup") { |q| q.default = "Y" } == "Y"
hostgroup = ask("What is the name of the hostgroup?") do |q|
q.validate = /.+/
q.responses[:not_valid] = "Should not be blank"
end
end
if hostgroup.nil? and mod.nil?
say("You need to set at least one hostgroup or module")
exit(-1)
end
default_branch = ask("Default branch?") { |q| q.default = "master" }
environment_path = ask("Environment path?") { |q| q.default = "/afs/cern.ch/user/l/lpigueir/private/repositories/new-punch-modules/it-puppet-environments/" }
overrides = {}
modules = {}
hostgroups = {}
unless mod.nil?
modules[mod] = env
overrides['modules'] = modules
end
unless hostgroup.nil?
hostgroups[hostgroup] = env
overrides['hostgroups'] = hostgroups
end
yaml_result = {}
yaml_result['default'] = default_branch
yaml_result['notifications'] = email
yaml_result['overrides'] = overrides
puts yaml_result
path_branch = ask("Path to create a new branch?") do |q|
q.gather = ""
end
say("Your new environment is: #{env}")
say("Your email is: #{email}")
say("The name of the module is: #{mod}") if mod
say("The name of the hostgroup is: #{hostgroup}") if hostgroup
say("The default branch is: #{default_branch}")
path_branch.each do |p|
say("Creating a branch #{env} in #{p}")
puts create_a_branch(env, p)
end
File.write(environment_path + "/" + env + ".yaml", yaml_result.to_yaml)
g = Git.open(environment_path, :log => Logger.new(STDOUT))
g.add(env + ".yaml")
g.commit("Added #{env} environment")
g.fetch
g.rebase("origin/master")
g.push("origin", "master")