This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
puppet.rb
149 lines (122 loc) · 5.66 KB
/
puppet.rb
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
module Vagrant
module Command
class PuppetMasterCommand < Vagrant::Command::GroupBase
register "puppetmaster", "Control a contained puppetmaster instance"
source_root File.expand_path("../templates", __FILE__)
desc "todo", "A todo list of that needs to be done to get this working"
def todo()
env.ui.info("@todo:")
env.ui.info("1. Add method to generate a config (thats working):: In progress")
env.ui.info("2. Read the stored configuration and use that to generate the config")
env.ui.info("3. Add method to start puppetmaster")
env.ui.info("4. Adjust configuration to autosign stuff etc etc. Make it useable!")
env.ui.info("5. Add method to stop puppetmaster")
env.ui.info("6. Add method to reset puppetmaster data (gets rid of everything but the configuration)")
end
desc "start", "Start a puppet master"
method_option :name, :aliases => '-n', :type => :string, :default => "puppetmaster",
:desc => 'A custom name for the puppetmaster. This is also used as target folder where the configuration will be setup.'
def start()
name = options[:name]
end
desc "genconfig", "Generate a puppetmaster configuration setup"
method_option :name, :aliases => '-n', :type => :string, :default => "puppetmaster",
:desc => 'A custom name for the puppetmaster. This is also used as target folder where the configuration will be setup.'
method_option :manifestdir, :aliases => '-m', :type => :string,
:desc => 'Where puppet master looks for his manifests. Defaults to ./manifests .'
method_option :modulepath, :aliases => '-p', :type => :string,
:desc => 'The search path for modules as a colon seperated list of directories. Defaults to ./modules .'
method_option :bindaddress, :aliases => '-b', :type => :string, :default => '',
:desc => 'Which address puppet master binds on.'
method_option :masterport, :aliases => '-p', :type => :numeric, :default => 8140,
:desc => 'Which port puppet master listens on.'
method_option :puppetport, :aliases => '-c', :type => :numeric, :default => 8139,
:desc => 'Which port pupet agent listens on.'
method_option :user, :aliases => '-u', :type => :string,
:desc => 'User name to run puppetmaster as. Defaults to current user.'
method_option :group, :aliases => '-g', :type => :string,
:desc => 'Group name to run puppet master as. Defaults to current group.'
def genconfig()
begin
require 'etc'
rescue LoadError
env.ui.error "Using genconfig requires the gem 'etc' installed."
exit
end
## todo: use env for user/group stuff and maybe hostname?
## todo: use some of the customization options (method_option) for defaulting these values below
name = options[:name]
env.ui.info "Generate the config: '#{name}"
env.ui.info "Target: ./#{name}/"
username = options[:user]
if ! username
username = Etc.getpwuid(Process.euid).name
end
groupname = options[:group]
if ! groupname
groupname = Etc.getgrgid(Process.egid).name
end
manifest_dir = options[:manifestdir]
if ! manifest_dir
manifest_dir = File.expand_path(File.join(".", "manifests"))
end
if File.exists?(File.join(manifest_dir, 'site.pp'))
initfile = 'site.pp'
else
initfile = 'init.pp'
end
module_path = options[:modulepath]
if ! module_path
module_path = File.expand_path(File.join(".", "modules"))
end
## Default is set by method_option
master_port = options[:masterport]
puppet_port = options[:puppetport]
opts = {
:name => name,
:rundir => "./#{name}/run",
:vardir => "./#{name}/var",
:confdir => "./#{name}/",
:config => "./#{name}/puppetmaster.conf",
:logdir => "./#{name}/logs",
:manifestdir => manifest_dir,
:modulepath => module_path,
:bindaddress => '',
:masterport => 8140,
:puppetport => 8139,
:puppet_user => username,
:puppet_group => groupname,
:initfile => initfile,
}
directory('puppetmaster', "./#{name}/", opts)
end
end
class PuppetCommand < Vagrant::Command::GroupBase
register "puppet", "Do all sorts of fun stuff with puppet"
source_root File.expand_path("../templates", __FILE__)
desc "master", "Control a contained puppetmaster instance"
subcommand "master", PuppetMasterCommand
desc "mkdirs", "Create a default puppet structure"
def mkdirs()
env.ui.info "Creating basic structure"
empty_directory "manifests"
empty_directory "modules"
opts = {}
template('puppet_init.tt', "manifests/init.pp", opts)
end
desc "module_create [NAME]", "Create a new puppet module structure"
def module_create(name)
env.ui.info "Create puppet module structure for new module '#{name}'"
empty_directory "modules/#{name}/templates"
empty_directory "modules/#{name}/manifests"
opts = { :name => "#{name}" }
template('module_init.tt', "modules/#{name}/manifests/init.pp", opts)
end
desc 'module_add [NAME]', 'Add an existing puppet module to your modules'
method_option :force, :aliases => '-f', :type => :boolean, :desc => "Force adding this module: overwrites existing module with same name"
def module_add(name)
env.ui.info "Adding module #{name}."
end
end
end
end