{"record":{"id":"b29bbca59dcf080b","repo":"puppetlabs/puppet","slug":"can-not-create-resource-title-parent-director","errorCode":null,"errorMessage":"Can not create #{@resource.title}; parent directory does not exist","messagePattern":"Can not create #(.+?); parent directory does not exist","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/type/file/ensure.rb","lineNumber":152,"sourceCode":"        should = source.checksum\n      else\n        should = property.should\n      end\n      if should == :absent\n        is = property.retrieve\n      else\n        is = :absent\n      end\n\n      property.change_to_s(is, should)\n    end\n\n    # Check that we can actually create anything\n    def check\n      basedir = File.dirname(@resource[:path])\n\n      if !Puppet::FileSystem.exist?(basedir)\n        raise Puppet::Error,\n              \"Can not create #{@resource.title}; parent directory does not exist\"\n      elsif !FileTest.directory?(basedir)\n        raise Puppet::Error,\n              \"Can not create #{@resource.title}; #{dirname} is not a directory\"\n      end\n    end\n\n    # We have to treat :present specially, because it works with any\n    # type of file.\n    def insync?(currentvalue)\n      unless currentvalue == :absent or resource.replace?\n        return true\n      end\n\n      if should == :present\n        !(currentvalue.nil? or currentvalue == :absent)\n      else\n        super(currentvalue)","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/type/file/ensure.rb#L134-L170","documentation":"ensure#check runs before syncing any creation (file, link, present). If File.dirname of the resource path does not exist, Puppet raises 'Can not create <title>; parent directory does not exist' — the same guard as the directory branch, applied to every ensure value that creates something.","triggerScenarios":"`file { '/opt/app/bin/tool': ensure => file, source => ... }` with /opt/app/bin absent; `ensure => link` under a nonexistent directory; `ensure => present` on a new nested path; parents managed later in the catalog without ordering.","commonSituations":"Fresh nodes where install directories are not provisioned yet; a module assuming a package creates the parent; purge workflows that removed the parent first; new modules applied before their prerequisite classes.","solutions":["Declare and order the parent directory resource before the child (require/before/->).","Create install roots in provisioning (package post-install, cloud-init, kickstart) or an early class.","Run `puppet agent -t --debug` to see exactly which parent path is reported missing.","For many nested files, manage the directory tree explicitly or use an ensure => directory root with source recursion."],"exampleFix":"// before\nfile { '/opt/app/bin/tool':\n  ensure => file,\n  source => 'puppet:///modules/app/tool',\n}\n\n// after\nfile { '/opt/app/bin': ensure => directory }\n->\nfile { '/opt/app/bin/tool':\n  ensure => file,\n  source => 'puppet:///modules/app/tool',\n}","handlingStrategy":"validation","validationCode":"# Ruby pre-flight\nbasedir = File.dirname(resource_path)\nfail(\"#{basedir} missing — provision it or add an ordered file resource\") unless Puppet::FileSystem.exist?(basedir)","typeGuard":null,"tryCatchPattern":"rescue Puppet::Error; on /parent directory does not exist/ add the parent directory resource with a before/require relationship to the failing resource and re-run the agent.","preventionTips":["Order parent creation before any child under it (require/before/->).","Provision install roots in early classes or cloud-init.","Watch fresh-node smoke tests — ordering bugs appear there first.","Consider a directory root with source recursion for deep trees."],"tags":["puppet","file","ensure","mkdir","ordering"],"backgroundTag":"missing-parent-directory","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}