Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-10214

Unexpected results on "replace => false" on symlinks

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Duplicate
    • Affects Version/s: PUP 5.5.17
    • Fix Version/s: None
    • Component/s: Catalog Application
    • Labels:
    • Template:
      PUP Bug Template
    • Agent OS:
      CentOS 7
    • Master OS:
      CentOS 7
    • Team:
      Coremunity
    • Method Found:
      Needs Assessment
    • QA Risk Assessment:
      Needs Assessment

      Description

      Puppet Version: 5.5.17-1.el7
      Puppet Server Version:5.3.10-1.el7
      OS Name/Version: Centos 7

      This is a copy of an old redmine ticket that was never resolved:

      https://projects.puppetlabs.com/issues/4872

      To summarize, if puppet contains a declaration:

      file { '/foo':
          ensure  => 'link',
          target  => '/bar'
          replace => false,
      }
      

      ...and '/foo' already exists as a dangling symlink (pointing to a file that does not exist), then puppet will change the symlink to point back to '/bar'.

      Desired Behavior:

      Puppet should respect replace => false and not replace the symlink.

      Actual Behavior:

      As described above, puppet replaces the symlink.

       

      I looked at the code and I think the current behavior is the same in master, though I don't have the means to test it myself. These parts seem relevant:

      lib/puppet/type/file/target.rb

           def insync?(currentvalue)
            if [:nochange, :notlink].include?(self.should) or @resource.recurse?
              return true
            elsif ! @resource.replace? and Puppet::FileSystem.exist?(@resource[:path])
              return true
            else
      

      lib/puppet/file_system.rb

        # Determines if a file exists by verifying that the file can be stat'd.
        # Will follow symlinks and verify that the actual target path exists.
        #
        # @return [Boolean] true if the named file exists.
        #
        # @api public
        #
        def self.exist?(path)
          @impl.exist?(assert_path(path))
        end 
      

      I think that for this functionality, the file resource code should instead use a function that does not follow symlinks. Puppet is supposed to be managing the symlink, and the target (present or not) is irrelevant. When creating a symlink, puppet correctly does not care if the target exists.

      Thanks,
      Corey

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              bugfood Corey Hickey
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support