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

3x functions cannot be called from deferred functions in puppet agent

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • PUP 6.17.0
    • PUP 6.20.0, PUP 7.3.0
    • None
    • Night's Watch
    • 2
    • NW - 2021-01-20
    • Needs Assessment
    • Bug Fix
    • Allows deferred 3.x functions like "file" and "sprintf" to be called during a "puppet agent" run. Previously, it only worked for "puppet apply" but not "puppet agent".
    • Needs Assessment

    Description

      sprintf is a builtin 3x function. The following works when running puppet apply:

      [root@keen-lecture ~]# cat /etc/puppetlabs/code/environments/production/manifests/site.pp
      notify { "deferred": message => Deferred("sprintf", ["hello"]) }
      [root@keen-lecture ~]# puppet apply /etc/puppetlabs/code/environments/production/manifests/site.pp
      Notice: Compiled catalog for keen-lecture.delivery.puppetlabs.net in environment production in 0.02 seconds
      Notice: hello
      Notice: /Stage[main]/Main/Notify[deferred]/message: defined 'message' as 'hello'
      Notice: Applied catalog in 0.01 seconds
      

      The same code doesn't work when running puppet agent and gives an unhelpful error:

      [root@keen-lecture ~]# puppet agent -t --trace
      Info: Using configured environment 'production'
      Info: Retrieving pluginfacts
      Info: Retrieving plugin
      Info: Retrieving locales
      Info: Loading facts
      Error: Failed to apply catalog: Function sprintf not defined despite being loaded!
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/scope.rb:1044:in `method_missing'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/functions.rb:751:in `block in call'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/functions.rb:748:in `catch'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/functions.rb:748:in `call'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_support.rb:283:in `block in external_call_function'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_support.rb:282:in `external_call_function'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/scope.rb:1101:in `call_function'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/deferred_resolver.rb:119:in `resolve_future'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/deferred_resolver.rb:89:in `resolve'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/deferred_resolver.rb:71:in `block (2 levels) in resolve_futures'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/deferred_resolver.rb:70:in `each_pair'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/deferred_resolver.rb:70:in `block in resolve_futures'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/deferred_resolver.rb:68:in `each'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/deferred_resolver.rb:68:in `resolve_futures'
      /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/deferred_resolver.rb:32:in `resolve_and_replace'
      

      It seems like we should either present a consistent error that 3x functions can't be deferred, or allow the agent to load 3x functions in the same way the apply does.

      The same problem also happens when using a 3x function from a module, eg bool2str from stdlib:

      notify { "deferred": message => Deferred("bool2str", [true]) }
      

      [root@keen-lecture ~]# puppet agent -t --trace
      Info: Using configured environment 'production'
      Info: Retrieving pluginfacts
      Info: Retrieving plugin
      Info: Retrieving locales
      Info: Loading facts
      Error: Failed to apply catalog: Function bool2str not defined despite being loaded!
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Zendesk Support