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

Puppet loses track of the current environment

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • None
    • PUP 6.0.0
    • None
    • None
    • The agent should only use its remote environment during the configurer run, so it should only load features, etc from its pluginsync'ed libdir and never from the modulepath for its configured environment.

    • Hide

      Puppet agent should never load types/providers from its modulepath, instead always loading them from its libdir (since it needs to use the same version of modules as the compiler used to generate the catalog).

      Puppet should continue to be able to load applications from modules. There is an acceptance test for this already.

      Puppet should always load features from the current environment. Previously it used the configured environment (so the agent could load the feature from a locally installed module, instead of what it pluginsynced).

      Show
      Puppet agent should never load types/providers from its modulepath, instead always loading them from its libdir (since it needs to use the same version of modules as the compiler used to generate the catalog). Puppet should continue to be able to load applications from modules. There is an acceptance test for this already. Puppet should always load features from the current environment. Previously it used the configured environment (so the agent could load the feature from a locally installed module, instead of what it pluginsynced).
    • Coremunity
    • Platform Core KANBAN
    • Needs Assessment
    • Bug Fix
    • Hide
      Puppet's autoloader methods now require a non-nil environment. This is a breaking API change, but should not affect any user extensions like 3x functions.
      Puppet sometimes used the configured environment instead of the current environment to autoload. This mainly affected agents when loading provider features.
      Calling Puppet::Parser::Functions.autoloader.load* methods are deprecated, and will issue a warning if strict mode is set to warning or error. Instead use Scope#call_function("myfunction") to call other functions from within a function.
      Show
      Puppet's autoloader methods now require a non-nil environment. This is a breaking API change, but should not affect any user extensions like 3x functions. Puppet sometimes used the configured environment instead of the current environment to autoload. This mainly affected agents when loading provider features. Calling Puppet::Parser::Functions.autoloader.load* methods are deprecated, and will issue a warning if strict mode is set to warning or error. Instead use Scope#call_function("myfunction") to call other functions from within a function.
    • Needs Assessment

    Description

      Puppet loses track of the current environment when calling the autoloader to load/find:

      • applications
      • features
      • parent providers that haven't been loaded yet, e.g. openbsd which is a parent of freebsd, where freebsd is loaded first because of its name.
      • termini

      Puppet then falls back to the configured environment (Puppet[:environment]), which may not match the current environment (Puppet.lookup(:current_environment)). For the agent specifically, it means we sometimes use the configured environment's modulepath which has a higher precedence than our libdir containing pluginsync'ed files. This is a problem, because when we include vendor_modules in the basemodulepath (see PUP-8582), we don't want that to have higher precedence that the libdir as the agent might load a type/provider that is incompatible with the type that the master used during compilation.

      To reproduce, create the following files on the master:

      [root@yhw77y0zn0j776u ~]# tree /etc/puppetlabs/code/environments/production/
      /etc/puppetlabs/code/environments/production/
      ├── data
      ├── environment.conf
      ├── hiera.yaml
      ├── manifests
      │   └── site.pp
      └── modules
          └── foo
              └── lib
                  └── puppet
                      ├── feature
                      │   └── foo.rb
                      ├── provider
                      │   └── foo
                      │       └── foo.rb
                      └── type
                          └── foo.rb
       
      10 directories, 6 files
      [root@yhw77y0zn0j776u ~]# find /etc/puppetlabs/code/environments/production/{manifests,modules} -type f -print -exec cat {} \;
      /etc/puppetlabs/code/environments/production/manifests/site.pp
      foo { 'hi': }
      /etc/puppetlabs/code/environments/production/modules/foo/lib/puppet/type/foo.rb
      Puppet::Type.newtype(:foo) do
        newparam(:name, namevar: true)
        newproperty(:message)
      end
      /etc/puppetlabs/code/environments/production/modules/foo/lib/puppet/feature/foo.rb
      Puppet.features.add(:foo, libs: ['pp'])
      /etc/puppetlabs/code/environments/production/modules/foo/lib/puppet/provider/foo/foo.rb
      Puppet::Type.type(:foo).provide(:foo) do
        confine :feature => :foo
       
        def message=(value)
          puts value
        end
       
        def message
          :absent
        end
      end
      

      On the agent which must be one a different host, create a bogus feature:

      $ tree ~/.puppetlabs/etc/code/environments/production/modules
      /Users/josh/.puppetlabs/etc/code/environments/production/modules
      └── foo
          └── lib
              └── puppet
                  └── feature
                      └── foo.rb
       
      4 directories, 1 file
      $ cat ~/.puppetlabs/etc/code/environments/production/modules/foo/lib/puppet/feature/foo.rb
      BOOM!!
      

      The agent run will fail, with the path to the bogus feature:

      $ bx puppet agent -t
      Info: Using configured environment 'production'
      Info: Retrieving pluginfacts
      Info: Retrieving plugin
      Info: Retrieving locales
      Info: Caching catalog for localhost
      Error: Could not autoload puppet/feature/foo: /Users/josh/.puppetlabs/etc/code/environments/production/modules/foo/lib/puppet/feature/foo.rb:1: syntax error, unexpected end-of-input
      Error: Failed to apply catalog: Could not autoload puppet/feature/foo: /Users/josh/.puppetlabs/etc/code/environments/production/modules/foo/lib/puppet/feature/foo.rb:1: syntax error, unexpected end-of-input
      

      Attachments

        Issue Links

          Activity

            People

              josh Josh Cooper
              josh Josh Cooper
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support