{"record":{"id":"7ceec91cdfe56098","repo":"puppetlabs/puppet","slug":"could-not-find-template-filename","errorCode":null,"errorMessage":"Could not find template '%{filename}'","messagePattern":"Could not find template '%(.+?)'","errorType":"exception","errorClass":"Puppet::ParseError","httpStatus":null,"severity":"error","filePath":"lib/puppet/parser/templatewrapper.rb","lineNumber":68,"sourceCode":"  end\n\n  # @return [Array<String>] The tags defined in the current scope\n  # @api public\n  def tags\n    raise NotImplementedError, \"Call 'all_tags' instead.\"\n  end\n\n  # @return [Array<String>] All the defined tags\n  # @api public\n  def all_tags\n    scope.catalog.tags\n  end\n\n  # @api private\n  def file=(filename)\n    @__file__ = Puppet::Parser::Files.find_template(filename, scope.compiler.environment)\n    unless @__file__\n      raise Puppet::ParseError, _(\"Could not find template '%{filename}'\") % { filename: filename }\n    end\n  end\n\n  # @api private\n  def result(string = nil)\n    if string\n      template_source = \"inline template\"\n    else\n      string = Puppet::FileSystem.read_preserve_line_endings(@__file__)\n      template_source = @__file__\n    end\n\n    # Expose all the variables in our scope as instance variables of the\n    # current object, making it possible to access them without conflict\n    # to the regular methods.\n    escaped_template_source = template_source.gsub(/%/, '%%')\n    benchmark(:debug, _(\"Bound template variables for %{template_source} in %%{seconds} seconds\") % { template_source: escaped_template_source }) do\n      scope.to_hash.each do |name, value|","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/parser/templatewrapper.rb#L50-L86","documentation":"Raised by TemplateWrapper#file= when Puppet::Parser::Files.find_template(filename, environment) returns nil for the requested template path. Template lookup resolves '<module>/<path>.erb' against the modules and templatedirs of the COMPILING environment; failure means no such file is visible to that environment. It is a Puppet::ParseError, so it aborts compilation with the exact requested filename in the message.","triggerScenarios":"`template('apache/vhost.erb')` or `file { ...: content => template('app/config.erb') }` where the module lacks templates/config.erb; wrong path casing; template in a module not installed in the compiling environment; `template('custom.erb')` relying on old templatedir behavior that no longer resolves.","commonSituations":"Compiling master missing a module present on the agent (environment drift between git branches); typos or renamed template files; modules vendored with different case on case-sensitive filesystems; migrating from Puppet 2/3 templatedir usage to module-based template paths.","solutions":["Verify the path maps to a real file: modules/<module>/templates/<path>.erb in the environment that compiles the node.","Check the module is installed in that environment (`puppet module list` / r10k checkout of the branch) and re-sync environments on all compile masters.","Fix casing/typos — template paths are case-sensitive on Linux masters.","For Puppet <4 layout issues, move templates under the module or use epp with the module loader; use inline_template('...') only for tiny strings, not to dodge missing files."],"exampleFix":"# before\nfile { '/etc/app.conf':\n  content => template('app/config.erb'),   # file actually at templates/app/conf.erb\n}\n\n# after\nfile { '/etc/app.conf':\n  content => template('app/conf.erb'),\n}","handlingStrategy":"validation","validationCode":"# Ruby API — probe before rendering:\npath = Puppet::Parser::Files.find_template('app/config.erb', env)\nrender(path) unless path.nil?\n# Shell — verify on the compiling master:\n#   ls /etc/puppetlabs/code/environments/<env>/modules/app/templates/config.erb","typeGuard":null,"tryCatchPattern":"begin\n  wrapper.file = 'app/config.erb'\nrescue Puppet::ParseError => e\n  # template missing in this environment — fall back to a packaged default\n  wrapper.result(default_template_string)\nend","preventionTips":["Verify module/template presence in the SAME environment that compiles the node (r10k/Puppetfile sync, all compile masters).","Automate a template-existence check in CI that mirrors template() calls against the module tree.","Use module-relative template paths ('module/path.erb') and avoid legacy templatedir reliance.","Watch casing — template paths are case-sensitive."],"tags":["puppet","templates","erb","module-path","environment"],"backgroundTag":"template-not-found","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}