Bug #8596

Title and name must be unique within a given resource.

Added by Joe McDonagh 10 months ago. Updated 6 months ago.

Status:Closed Start date:07/23/2011
Priority:Urgent Due date:
Assignee:Nick Lewis % Done:

0%

Category:RAL
Target version:2.6.13
Affected Puppet version:2.6.0 Branch:
Keywords:file path
Votes: 1

Description

I discovered today that a catalog will compile if two files have the same path yet different namevars. Not sure if this is on purpose for some reason I can’t think of, or what.

History

Updated by Luke Kanies 10 months ago

  • Category set to RAL
  • Status changed from Unreviewed to Accepted
  • Priority changed from Normal to High

This is definitely critical. What version are you seeing this with?

Updated by Joe McDonagh 10 months ago

Sorry, forgot to set it in the ticket, 2.6.7.

Updated by Luke Kanies 10 months ago

  • Status changed from Accepted to Needs More Information

Can you clarify this a bit? I just tested duplicate files with every combination of duplication I could think of and I still get failures. What’s your failing code?

Updated by Joe McDonagh 10 months ago

Hey Luke, sure. Doing this in a hurry sorry for the diff markers in the pastes

-    # This is temporary until a more elegant solution for users can be written
-    file {
-        "bashrc-jmcdonagh":
-            group   => "web",
-            mode    => "600",
-            owner   => "jmcdonagh",
-            path    => "/home/jmcdonagh/.bashrc",
-            require => User::Devuser["jmcdonagh"],
-            source  => "puppet:///dist/users/bashrc-jmcdonagh";
-        "vimrc-jmcdonagh":
-            group   => "web",
-            mode    => "600",
-            owner   => "jmcdonagh",
-            path    => "/home/jmcdonagh/.vimrc",
-            require => User::Devuser["jmcdonagh"],
-            source  => "puppet:///dist/users/vimrc-jmcdonagh";
-    }

I had been putting off adding a parameter for serving profiles in the devuser define, and got around to it this weekend:

+        if ($ensure == "present" and $dotfiles == "true") {
+            file {
+                "/home/${name}/.bash_profile":
+                    ensure  => "present",
+                    group   => "web",
+                    mode    => "600",
+                    owner   => "${name}",
+                    source  => "puppet:///modules/user/user_profiles/${name}/bash_profile";
+                "/home/${name}/.bashrc":
+                    ensure  => "present",
+                    group   => "web",
+                    mode    => "600",
+                    owner   => "${name}",
+                    source  => "puppet:///modules/user/user_profiles/${name}/bashrc";
+            }
+        }

Updated by Joe McDonagh 10 months ago

The vimrc I pasted in by accident, the bashrc is the conflicting one, and the resource in the second past is inside a defined resource, not sure if that matters.

Updated by Stefan Schulte 10 months ago

  • Affected Puppet version set to 2.6.0

I was able to reproduce the issue with 2.6.0 and 2.7.2rc1. The error was not reproduceable with 0.25.5

0.25.5

Duplicate definition: File[/tmp/foo] is already defined in file /tmp/test.pp at line 8; cannot redefine

2.6.0

notice: /Stage[main]//File[/tmp/foo]/ensure: create
notice: /Stage[main]//File[same_file]/ensure: removed

sample manifest:

file { '/tmp/foo':
  ensure => file,
}

file { 'same_file':
  path   => '/tmp/foo',
  ensure => absent,
}

Updated by Stefan Schulte 10 months ago

FWIW: In my opinion it is not a bug, because the title is what matters (at least that is my understanding).

And reading http://docs.puppetlabs.com/guides/language_guide.html:

[...]
The field before the colon is the resource’s title, which must be unique and can be used to refer
to the resource in other parts of the Puppet configuration
[...]
It’s important to note here that the title alone identifies the resource. Even if the resource seems
to conceptually point to the same entity, it’s the title that matters. The following is possible in Puppet,
but is to be avoided as it can lead to errors once things get sent down to the client.

    file { 'sshdconfig':
      name  => '/usr/local/etc/ssh/sshd_config',
      owner => 'root',
    }

    file { '/usr/local/etc/ssh/sshd_config':
      owner => 'sshd',
    }

Updated by Luke Kanies 10 months ago

This is absolutely a bug, and the docs there are wrong.

Both title and name need to be unique within a given resource type.

Updated by Nigel Kersten 10 months ago

  • Status changed from Needs More Information to Accepted
  • Target version set to 2.6.x

What Luke said. Chasing down the doc history to work out whether there’s a clear path to why this changed, but this is definitely going to be prioritized to be fixed in both 2.6.x (for the last release) and 2.7.x.

Updated by Nigel Kersten 10 months ago

  • Priority changed from High to Urgent

Updated by Nick Lewis 10 months ago

  • Assignee set to Nick Lewis

Updated by Nigel Kersten 10 months ago

  • Subject changed from File resource should probably use path as a secondary unique key to Title and name must be unique within a given resource.

Updated by Nick Lewis 10 months ago

  • Status changed from Accepted to Merged - Pending Release

Merged fix to 2.6.x in commit:0157bf3ee2d53173874e37da9848b2753d428a25.

The introduction of composite namevars caused the resource title used in
resource aliases to be set as an array, even when the resource only had one
namevar. This would fail to conflict with non-alias entries in the resource
table, which used a string for the title, even though the single element array
contained the same string.

Now, we flatten the key used in the resource table, so that single element
arrays are represented as strings, and will properly conflict with resource
titles.

Also merged to 2.7.x in commit:8baa4897e777f9515dc1663317f432ace3067bae and master in commit:b13427b56d8529731d0334d420b24a592ecb43ea.

Updated by Nick Fagerlund 10 months ago

And I’ve fixed the documentation by… deleting a paragraph from the language guide.

Updated by Michael Stahnke 10 months ago

  • Status changed from Merged - Pending Release to Closed

Shipped as part of 2.7.3rc1

Updated by James Turnbull 9 months ago

  • Target version changed from 2.6.x to 2.7.3

Updated by Nigel Kersten 9 months ago

  • Target version changed from 2.7.3 to 2.6.x

This actually went to 2.6.x

Updated by James Turnbull 9 months ago

  • Target version changed from 2.6.x to 2.6.10

Updated by Matthaus Litteken 6 months ago

released in 2.6.13rc1

Updated by Matthaus Litteken 6 months ago

  • Target version changed from 2.6.10 to 2.6.13

Also available in: Atom PDF