The Puppet Labs Issue Tracker has Moved:

This issue tracker is now in read-only archive mode and automatic ticket export has been disabled. Redmine users will need to create a new JIRA account to file tickets using See the following page for information on filing tickets with JIRA:

Bug #10704

puppet's idea of /etc/hosts management does not match real world use

Added by Bill Tong over 4 years ago. Updated almost 2 years ago.

Status:AcceptedStart date:11/10/2011
Priority:HighDue date:
Assignee:-% Done:


Target version:3.x
Affected Puppet version:2.7.6 Branch:

We've Moved!

Ticket tracking is now hosted in JIRA:

This ticket is now tracked at:


Here is a valid extract from an /etc/hosts files on a RHEL box:   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

Here is the code to make puppet add these entries:

    host { 'localhost':
            ip => '',
            host_aliases => [ 'localhost.localdomain',
                    'localhost4', 'localhost4.localdomain4', ],

   host { 'localhost':
           ip => '::1',
           host_aliases => [ 'localhost.localdomain',
                   'localhost6', 'localhost6.localdomain6', ],

Notice the “localhost” part is the same in both cases. This causes a problem:

Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate definition: Host[localhost] is already defined in file /etc/puppet/modules/networking/manifests/init.pp


Related issues

Related to Puppet - Feature #9454: The host type should allow multiple IP addresses for a host Accepted 09/13/2011


#1 Updated by Bill Tong over 4 years ago

Note: the presence of just the first host{} entry will delete the ipv6 entry from /etc/hosts – not good!

#2 Updated by Cody Herriges over 4 years ago

Because of the model that Puppet follows and its requirement of uniqueness this is a tricky thing to satisfy without the breakdown of Puppet’s declarative operation. In this specific case, either each line would have to be accompanied by a unique comment or each entry needs a composite namevar. My latest attempt at getting composite namevars into Puppet can be found at, based off another PSE’s attempt at the same problem. Composite namevars still needs a lot of work. My code functions in my smoke testing but causes ~800 Puppet unit and spec tests to fail.

#3 Updated by Cody Herriges over 4 years ago

  • Status changed from Unreviewed to Needs Decision

#4 Updated by Bill Tong over 4 years ago

Can’t the key for the hostfile be based on both the ip and the hostname together?

#5 Updated by Anonymous over 4 years ago

  • Assignee set to Nigel Kersten

Bil Tong wrote:

Can’t the key for the hostfile be based on both the ip and the hostname together?

Actually, the model of /etc/hosts is inconsistent, where some platforms filter duplicate entries and others don’t, based any of the fields.

The least worst model is that the IP address, of which there is one record per line, is the unique key, and the official name and aliases hang from that; this exposes the platform inconsistency around handling duplicate hostname entries to the user, but isn’t too terrible.

The parser should be tolerant of duplicate IP rows, however, and merge those into a uniqified set of host names and aliases.

That would give the least worst behaviour given the way that different platforms handle this content.

In other words: the bug as reported is correct, and our model is not consistent with the real world needs for management of entries in /etc/hosts.

#6 Updated by Nigel Kersten about 4 years ago

  • Status changed from Needs Decision to Accepted
  • Assignee deleted (Nigel Kersten)
  • Priority changed from Normal to High
  • Target version set to 3.x

I’d like to target this at a version earlier than Telly, but I can’t see how we could do this without changing behavior significantly.

Am I being too paranoid?

#7 Updated by James Turnbull about 4 years ago

Daniel’s comments seem to suggest we can work around this is in the host parsedfile provider? Or Daniel do you mean the parser itself?

#8 Updated by Anonymous about 4 years ago

James Turnbull wrote:

Daniel’s comments seem to suggest we can work around this is in the host parsedfile provider? Or Daniel do you mean the parser itself?

No, Nigel is right: the current model is broken and needs to be replaced. This is an incompatible change, and is effectively completely replacing the hosts type. It is the correct change, of course, but that doesn’t make it any less costly.

My comment about the parser is related to the need to handle the malformed data that will be found in the real world, as well as to reflect the inconsistent cross-platform behaviour in the face of that malformed data.

(Also, none of the proposed multi-key bits are any more correct; they break things worse, making the whole problem harder to solve in the long term.)

#9 Updated by Philip Wigg over 3 years ago

I would just like to add that Windows seems to have a limit of nine host aliases per line.

So if you want to alias more than nine hosts to an IP, you need multiple lines starting with the same IP address.

#10 Updated by Martin Hagström almost 2 years ago

Redmine Issue #10704 has been migrated to JIRA:

Also available in: Atom PDF