Bug #1554
Puppetmaster throws exception if client has undefined hostname
| Status: | Closed | Start date: | 09/04/2008 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | node | |||
| Target version: | 0.24.6 | |||
| Affected Puppet version: | 0.24.5 | Branch: | ||
| Keywords: | ||||
| Votes: | 0 |
Description
The following code in lib/puppet/node.rb (names) tries to find names to refer to a client by if an FQDN wasn’t provided by the client:
# First, get the fqdn
unless fqdn = parameters["fqdn"]
if domain = parameters["domain"]
fqdn = parameters["hostname"] + "." + parameters["domain"]
end
end
In addition to assignment in conditionals being an abomination against mankind, under most (all?) circumstances, when the FQDN is undefined, the hostname is also undefined.
This results in fun errors like the following:
undefined method `+' for nil:NilClass on node XXXXX-XXXXXXX-XXXXXXX-XXXX
Which prevents clients from getting a compiled configuration from the puppetmaster daemon.
The fix is quite simple:
if parameters["hostname"] and parameters["domain"] fqdn = parameters["hostname"] + "." + parameters["domain"] else Puppet.warning "Host is missing hostname and/or domain: %s" % name end
Cheers, -P
History
Updated by James Turnbull over 3 years ago
- Status changed from Unreviewed to Code Insufficient
But doesn’t this ignore the fact that you might actually already have the fqdn?
Updated by Nigel Kersten over 3 years ago
ah, crossed wires, that snippet is meant to replace the inside test, so the complete replacement is
# First, get the fqdn
unless fqdn = parameters["fqdn"]
if parameters["hostname"] and parameters["domain"]
fqdn = parameters["hostname"] + "." + parameters["domain"]
else
Puppet.warning "Host is missing hostname and/or domain: %s" % name
end
end
Updated by Philip Walls over 3 years ago
Sorry for the confusion, the code nigelk2 posted above is on the money. I had intended to post the original patch but had to run out of the office in a hurry. Attaching the original patch now for completeness.
It’s worth noting that the outer unless block isn’t actually necessary with the current crop of Puppet clients. Based on my limited observation the client will never have an FQDN set if the hostname isn’t set, so that block becomes redundant.
-P
Updated by James Turnbull over 3 years ago
- Status changed from Code Insufficient to Closed
- Target version set to 0.24.6
Pushed in commit:8fe033820875966106ab3807aa34a1cafc85cbd2 in branch 0.24.x