summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-03-02 17:12:26 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-03-02 17:12:26 +0000
commit1a93c822667e6990b45f843e56d8976c51517671 (patch)
treeb7764e684b080f27158dfc7430ab30624db15568 /lib
parent95856eaaf02361ff597ca2c85e51cf141fe81280 (diff)
downloadpuppet-1a93c822667e6990b45f843e56d8976c51517671.tar.gz
puppet-1a93c822667e6990b45f843e56d8976c51517671.tar.xz
puppet-1a93c822667e6990b45f843e56d8976c51517671.zip
Fixing #68. After tons and tons and tons of work, everything successfully configures itself, and the --genmanifest argument should actually work. User and group creation will not necessarily work everywhere (in particular, Puppet uses dependencies to create the group first, but Fedora complains on user creation if the group already exists), but file and directory creation should. The only downside is that there is a decent amount of extra information printed on daemon startup, as the daemon checks its config; this could maybe be seen as a bonus, though, I guess.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@966 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet.rb3
-rw-r--r--lib/puppet/config.rb16
-rw-r--r--lib/puppet/log.rb3
-rwxr-xr-xlib/puppet/sslcertificates.rb19
-rw-r--r--lib/puppet/statechange.rb3
-rw-r--r--lib/puppet/type.rb1
-rwxr-xr-xlib/puppet/type/group.rb69
-rwxr-xr-xlib/puppet/type/nameservice.rb22
-rw-r--r--lib/puppet/type/nameservice/objectadd.rb4
-rwxr-xr-xlib/puppet/type/pfile/ensure.rb8
-rwxr-xr-xlib/puppet/type/user.rb69
-rw-r--r--lib/puppet/util.rb20
12 files changed, 188 insertions, 49 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb
index a3ff166bc..289320776 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -124,8 +124,7 @@ module Puppet
},
:statefile => { :default => "$statedir/state.yaml",
:mode => 0660,
- :owner => "$user",
- :owner => "$group",
+ :group => "$group",
:desc => "Where puppetd and puppetmasterd store state associated
with the running configuration. In the case of puppetmasterd,
this file reflects the state discovered through interacting
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb
index 06aebb893..e38e26517 100644
--- a/lib/puppet/config.rb
+++ b/lib/puppet/config.rb
@@ -326,6 +326,7 @@ class Config
newobj.tag(section)
else
newobj = TransObject.new(name, type.to_s)
+ newobj.tags = ["puppet", "configuration", section]
newobj[:ensure] = "present"
done[type][name] = newobj
objects << newobj
@@ -476,8 +477,11 @@ Generated on #{Time.now}.
bucket = Puppet::TransBucket.new
bucket.type = "puppetconfig"
bucket.top = true
+
+ # Create a hash to keep track of what we've done so far.
+ @done = Hash.new { |hash, key| hash[key] = {} }
runners.each do |section|
- bucket.push section_to_transportable(section, nil, false)
+ bucket.push section_to_transportable(section, @done, false)
end
objects = bucket.to_type
@@ -486,15 +490,11 @@ Generated on #{Time.now}.
trans = objects.evaluate
trans.evaluate
- # And then clean up. We're now a tree of objects, so we have to
- # use delve, instead of each.
- #objects.delve do |object|
+ # Remove is a recursive process, so it's sufficient to just call
+ # it on the component.
objects.remove
- #trans.objects.each do |object|
- # object.remove(true)
- #end
- sections.each { |s| @used << s }
+ runners.each { |s| @used << s }
end
end
diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb
index ec7ec9e8b..6b8a55c18 100644
--- a/lib/puppet/log.rb
+++ b/lib/puppet/log.rb
@@ -28,7 +28,8 @@ module Puppet
}
#@destinations = {:syslog => Syslog.open("puppet")}
- @destinations = {:console => :console}
+ #@destinations = {:console => :console}
+ @destinations = {}
# Reset all logs to basics. Basically just closes all files and undefs
# all of the other objects.
diff --git a/lib/puppet/sslcertificates.rb b/lib/puppet/sslcertificates.rb
index 88a9193d1..a56e64add 100755
--- a/lib/puppet/sslcertificates.rb
+++ b/lib/puppet/sslcertificates.rb
@@ -12,12 +12,19 @@ module Puppet::SSLCertificates
Puppet.setdefaults("certificates",
:certdir => ["$ssldir/certs", "The certificate directory."],
:publickeydir => ["$ssldir/public_keys", "The public key directory."],
- :privatekeydir => ["$ssldir/private_keys", "The private key directory."],
- :privatedir => ["$ssldir/private",
- "Where the client stores private certificate information."],
- :passfile => ["$privatedir/password",
- "Where puppetd stores the password for its private key. Generally
- unused."]
+ :privatekeydir => { :default => "$ssldir/private_keys",
+ :mode => 0750,
+ :desc => "The private key directory."
+ },
+ :privatedir => { :default => "$ssldir/private",
+ :mode => 0750,
+ :desc => "Where the client stores private certificate information."
+ },
+ :passfile => { :default => "$privatedir/password",
+ :mode => 0640,
+ :desc => "Where puppetd stores the password for its private key.
+ Generally unused."
+ }
)
#def self.mkcert(type, name, days, issuercert, issuername, serial, publickey)
diff --git a/lib/puppet/statechange.rb b/lib/puppet/statechange.rb
index 5fdf407d2..c18cdd25c 100644
--- a/lib/puppet/statechange.rb
+++ b/lib/puppet/statechange.rb
@@ -131,9 +131,6 @@ module Puppet
[@state.is.inspect, @state.should.inspect]
return nil
end
-
- #raise "Moving statechanges backward is currently unsupported"
- #@type.change(@path,@should,@is)
end
def noop
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 4dda52c06..0e163adaf 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -1073,6 +1073,7 @@ class Type < Puppet::Element
# necessary. FIXME This method should be responsible for most of the
# error handling.
def self.create(hash)
+ #Puppet.warning "Creating %s" % hash.inspect
# Handle this new object being implicit
implicit = hash[:implicit] || false
if hash.include?(:implicit)
diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb
index 344614190..4e0bc4344 100755
--- a/lib/puppet/type/group.rb
+++ b/lib/puppet/type/group.rb
@@ -35,6 +35,75 @@ module Puppet
@parentmodule = Puppet::NameService::ObjectAdd
end
+ newstate(:ensure, @parentstate) do
+ newvalue(:present) do
+ self.syncname(:present)
+ end
+
+ newvalue(:absent) do
+ self.syncname(:absent)
+ end
+
+ desc "The basic state that the object should be in."
+
+ # If they're talking about the thing at all, they generally want to
+ # say it should exist.
+ #defaultto :present
+ defaultto do
+ if @parent.managed?
+ :present
+ else
+ nil
+ end
+ end
+
+ def change_to_s
+ begin
+ if @is == :absent
+ return "created"
+ elsif self.should == :absent
+ return "removed"
+ else
+ return "%s changed '%s' to '%s'" %
+ [self.name, self.is_to_s, self.should_to_s]
+ end
+ rescue Puppet::Error, Puppet::DevError
+ raise
+ rescue => detail
+ raise Puppet::DevError,
+ "Could not convert change %s to string: %s" %
+ [self.name, detail]
+ end
+ end
+
+ def retrieve
+ if @parent.exists?
+ @is = :present
+ else
+ @is = :absent
+ end
+ end
+
+ # The default 'sync' method only selects among a list of registered
+ # values.
+ def sync
+ if self.insync?
+ self.info "already in sync"
+ return nil
+ #else
+ #self.info "%s vs %s" % [self.is.inspect, self.should.inspect]
+ end
+ unless self.class.values
+ self.devfail "No values defined for %s" %
+ self.class.name
+ end
+
+ # Set ourselves to whatever our should value is.
+ self.set
+ end
+
+ end
+
newstate(:gid, @parentstate) do
desc "The group ID. Must be specified numerically. If not
specified, a number will be picked, which can result in ID
diff --git a/lib/puppet/type/nameservice.rb b/lib/puppet/type/nameservice.rb
index 9a9b280e5..3d323d138 100755
--- a/lib/puppet/type/nameservice.rb
+++ b/lib/puppet/type/nameservice.rb
@@ -19,22 +19,6 @@ class Type
end
end
end
-
- # Create the object. We have to call the 'syncname' method
- # on one of the non-ensure states, because the ensure state is not
- # a subclass of NSSState. Just find the first one and call it.
- def create
- @states.find { |name, state|
- state.is_a?(Puppet::State::NSSState)
- }[1].syncname(:present)
- end
-
- # Remove it
- def destroy
- @states.find { |name, state|
- state.is_a?(Puppet::State::NSSState)
- }[1].syncname(:absent)
- end
end
end
@@ -175,7 +159,7 @@ class State
when :absent
# we need to remove the object...
unless @parent.exists?
- @parent.info "already absent"
+ self.info "already absent"
# the object already doesn't exist
return nil
end
@@ -186,7 +170,7 @@ class State
type = "delete"
when :present
if @parent.exists?
- @parent.info "already exists"
+ self.info "already exists"
# The object already exists
return nil
end
@@ -207,7 +191,7 @@ class State
# we want object creation to show up as one event,
# not many
unless self.class.allatonce?
- Puppet.debug "%s is not allatonce" % self.class.name
+ Puppet.debug "%s is not allatonce" % @parent.class.name
if type == "create"
@parent.eachstate { |state|
state.sync
diff --git a/lib/puppet/type/nameservice/objectadd.rb b/lib/puppet/type/nameservice/objectadd.rb
index 2d88d24f1..fc866f193 100644
--- a/lib/puppet/type/nameservice/objectadd.rb
+++ b/lib/puppet/type/nameservice/objectadd.rb
@@ -17,7 +17,7 @@ module Puppet
# Does the object already exist?
def self.exists?(obj)
- if obj.getinfo
+ if obj.getinfo(true)
return true
else
return false
@@ -62,7 +62,7 @@ module Puppet
cmd = ["groupadd"]
if gid = @parent.should(:gid)
unless gid == :auto
- cmd << self.class.objectaddflag << gid
+ cmd << @parent.state(:gid).class.objectaddflag << gid
end
end
cmd << @parent[:name]
diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/pfile/ensure.rb
index dfef404db..6d0da89e7 100755
--- a/lib/puppet/type/pfile/ensure.rb
+++ b/lib/puppet/type/pfile/ensure.rb
@@ -27,7 +27,9 @@ module Puppet
Puppet::Util.asuser(asuser(), @parent.should(:group)) {
f = nil
if mode
- f = File.open(@parent[:path],"w", mode)
+ Puppet::Util.withumask(000) do
+ f = File.open(@parent[:path],"w", mode)
+ end
else
f = File.open(@parent[:path],"w")
end
@@ -52,7 +54,9 @@ module Puppet
end
Puppet::Util.asuser(asuser()) {
if mode
- Dir.mkdir(@parent[:path],mode)
+ Puppet::Util.withumask(000) do
+ Dir.mkdir(@parent[:path],mode)
+ end
else
Dir.mkdir(@parent[:path])
end
diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb
index ed9c79211..ea80f7f0b 100755
--- a/lib/puppet/type/user.rb
+++ b/lib/puppet/type/user.rb
@@ -17,8 +17,73 @@ module Puppet
@parentmodule = Puppet::NameService::ObjectAdd
end
- # The 'create' and 'destroy' methods are defined in type/nameservice.rb
- self.ensurable()
+ newstate(:ensure, @parentstate) do
+ newvalue(:present) do
+ self.syncname(:present)
+ end
+
+ newvalue(:absent) do
+ self.syncname(:absent)
+ end
+
+ desc "The basic state that the object should be in."
+
+ # If they're talking about the thing at all, they generally want to
+ # say it should exist.
+ #defaultto :present
+ defaultto do
+ if @parent.managed?
+ :present
+ else
+ nil
+ end
+ end
+
+ def change_to_s
+ begin
+ if @is == :absent
+ return "created"
+ elsif self.should == :absent
+ return "removed"
+ else
+ return "%s changed '%s' to '%s'" %
+ [self.name, self.is_to_s, self.should_to_s]
+ end
+ rescue Puppet::Error, Puppet::DevError
+ raise
+ rescue => detail
+ raise Puppet::DevError,
+ "Could not convert change %s to string: %s" %
+ [self.name, detail]
+ end
+ end
+
+ def retrieve
+ if @parent.exists?
+ @is = :present
+ else
+ @is = :absent
+ end
+ end
+ # The default 'sync' method only selects among a list of registered
+ # values.
+ def sync
+ if self.insync?
+ self.info "already in sync"
+ return nil
+ #else
+ #self.info "%s vs %s" % [self.is.inspect, self.should.inspect]
+ end
+ unless self.class.values
+ self.devfail "No values defined for %s" %
+ self.class.name
+ end
+
+ # Set ourselves to whatever our should value is.
+ self.set
+ end
+
+ end
newstate(:uid, @parentstate) do
desc "The user ID. Must be specified numerically. For new users
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 419b4892e..fd283539b 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -164,13 +164,15 @@ module Util
end
end
else
- unless obj = Puppet.type(:group)[group]
+ if obj = Puppet.type(:group)[group]
+ obj[:check] = [:gid]
+ else
obj = Puppet.type(:group).create(
:name => group,
:check => [:gid]
)
- obj.retrieve
end
+ obj.retrieve
end
if obj
gid = obj.should(:gid) || obj.is(:gid)
@@ -207,10 +209,10 @@ module Util
else
unless obj = Puppet.type(:user)[user]
obj = Puppet.type(:user).create(
- :name => user,
- :check => [:uid, :gid]
+ :name => user
)
end
+ obj[:check] = [:uid, :gid]
end
if obj
@@ -281,6 +283,16 @@ module Util
raise ArgumentError, "'%s' must be a string or symbol" % value
end
end
+
+ def self.withumask(mask)
+ cur = File.umask(mask)
+
+ begin
+ yield
+ ensure
+ File.umask(cur)
+ end
+ end
end
end