summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-06-02 16:24:16 -0700
committerNick Lewis <nick@puppetlabs.com>2011-06-06 15:49:38 -0700
commit1c70f0ce54022b55119b9e2d6d60cd1ae9bc019e (patch)
tree35a7c2372773859c688cc4778a7c5507221553fa /lib/puppet
parentc629958fb45f9ae3581f01835bf89654dd7967b7 (diff)
downloadpuppet-1c70f0ce54022b55119b9e2d6d60cd1ae9bc019e.tar.gz
puppet-1c70f0ce54022b55119b9e2d6d60cd1ae9bc019e.tar.xz
puppet-1c70f0ce54022b55119b9e2d6d60cd1ae9bc019e.zip
(#2128) Add support for setting node name based on a fact
This adds the node_name_fact setting, which specifies a fact to use to determine the node name. This allows dynamically determining the node name without having to modify puppet.conf or command line options. Using this setting requires modifying auth.conf to allow nodes to request catalogs not matching their certnames. For example, this would allow any authenticated node to retrieve any catalog: # $confdir/auth.conf path ~ /catalog/.+ allow * The node_name_fact and node_name_value options are mutually exclusive, because it is ambiguous which setting should take precedence. Paired-With: Jacob Helwig <jacob@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/application/apply.rb5
-rw-r--r--lib/puppet/configurer/fact_handler.rb7
-rw-r--r--lib/puppet/defaults.rb8
3 files changed, 19 insertions, 1 deletions
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 3f423a4c4..717935640 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -89,6 +89,11 @@ class Puppet::Application::Apply < Puppet::Application
raise "Could not find facts for #{Puppet[:node_name_value]}"
end
+ unless Puppet[:node_name_fact].empty?
+ Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
+ facts.name = Puppet[:node_name_value]
+ end
+
# Find our Node
unless node = Puppet::Node.find(Puppet[:node_name_value])
raise "Could not find node #{Puppet[:node_name_value]}"
diff --git a/lib/puppet/configurer/fact_handler.rb b/lib/puppet/configurer/fact_handler.rb
index 4d80e17b6..77bd1e5f1 100644
--- a/lib/puppet/configurer/fact_handler.rb
+++ b/lib/puppet/configurer/fact_handler.rb
@@ -16,7 +16,12 @@ module Puppet::Configurer::FactHandler
# compile them and then "cache" them on the server.
begin
reload_facter
- Puppet::Node::Facts.find(Puppet[:node_name_value])
+ facts = Puppet::Node::Facts.find(Puppet[:node_name_value])
+ unless Puppet[:node_name_fact].empty?
+ Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
+ facts.name = Puppet[:node_name_value]
+ end
+ facts
rescue SystemExit,NoMemoryError
raise
rescue Exception => detail
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 17c2850e5..4502dae16 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -487,6 +487,14 @@ module Puppet
setdefaults(:agent,
:node_name_value => ["$certname", "The name of the node."],
+ :node_name_fact => { :default => "",
+ :desc => "The fact to use as the node name.",
+ :hook => proc do |value|
+ if !value.empty? and Puppet[:node_name_value] != Puppet[:certname]
+ raise "Cannot specify both the node_name_value and node_name_fact settings"
+ end
+ end
+ },
:localconfig => { :default => "$statedir/localconfig",
:owner => "root",
:mode => 0660,