{"record":{"id":"76fa984c047e0480","repo":"puppetlabs/puppet","slug":"cannot-create-resource-path-parent-director","errorCode":null,"errorMessage":"Cannot create #{@resource[:path]}; parent directory #{parent} does not exist","messagePattern":"Cannot create #(.+?); parent directory #(.+?) does not exist","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/type/file/ensure.rb","lineNumber":86,"sourceCode":"        property.sync\n      else\n        @resource.write\n        @resource.should(:mode)\n      end\n    end\n\n    # aliasvalue(:present, :file)\n    newvalue(:present, :event => :file_created) do\n      # Make a file if they want something, but this will match almost\n      # anything.\n      set_file\n    end\n\n    newvalue(:directory, :event => :directory_created) do\n      mode = @resource.should(:mode)\n      parent = File.dirname(@resource[:path])\n      unless Puppet::FileSystem.exist? parent\n        raise Puppet::Error,\n              \"Cannot create #{@resource[:path]}; parent directory #{parent} does not exist\"\n      end\n      if mode\n        Puppet::Util.withumask(0o00) do\n          Dir.mkdir(@resource[:path], symbolic_mode_to_int(mode, 0o755, true))\n        end\n      else\n        Dir.mkdir(@resource[:path])\n      end\n      @resource.send(:property_fix)\n      return :directory_created\n    end\n\n    newvalue(:link, :event => :link_created, :required_features => :manages_symlinks) do\n      property = resource.property(:target)\n      fail \"Cannot create a symlink without a target\" unless property\n\n      property.retrieve","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/type/file/ensure.rb#L68-L104","documentation":"The ensure property's :directory value creates the target with Dir.mkdir, which (unlike `mkdir -p`) cannot create intermediate directories. Puppet guards this explicitly: if File.dirname of the resource path does not exist it raises 'Cannot create <path>; parent directory <parent> does not exist' instead of surfacing Errno::ENOENT.","triggerScenarios":"`file { '/data/app/logs': ensure => directory }` when /data/app does not exist yet; the parent resource exists in the catalog but is ordered after the child (missing require/before/->); a typo in one path segment; parents present on some nodes but not others.","commonSituations":"Assuming recursive mkdir -p semantics; fresh nodes missing mount points or install roots; ordering bugs where the parent directory resource lacks a relationship arrow; modules assuming a package created the parent.","solutions":["Declare each parent and order it: `file { '/data/app': ensure => directory } -> file { '/data/app/logs': ensure => directory }`.","Add `require => File['/data/app']` on the child (or `before` on the parent).","For deep trees, generate one resource per level with a defined type.","Re-read the reported parent path for typos — a misspelled segment looks identical to a missing one."],"exampleFix":"// before\nfile { '/data/app/logs': ensure => directory }\n\n// after: create and order each parent\nfile { '/data':     ensure => directory }\nfile { '/data/app': ensure => directory }\n->\nfile { '/data/app/logs': ensure => directory }","handlingStrategy":"validation","validationCode":"# Ruby pre-flight\nparent = File.dirname(target_path)\nunless Puppet::FileSystem.exist?(parent)\n  fail(\"#{parent} does not exist — declare file { '#{parent}': ensure => directory } and order it first\")\nend","typeGuard":null,"tryCatchPattern":"rescue Puppet::Error; on /parent directory .* does not exist/ add the missing parent as an ordered file resource and re-run — the catalog converges incrementally, no manual cleanup needed.","preventionTips":["Declare every path level and chain with -> arrows.","Never assume mkdir -p semantics.","Test manifests with rspec-puppet against a fresh tmpdir.","Re-check the reported parent path for typos."],"tags":["puppet","file","directory","mkdir","ordering"],"backgroundTag":"missing-parent-directory","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}