A collection of task oriented solutions in Puppet


You want to create a directory


You want to create a new directory


class directories {

  # create a directory
  file { '/etc/site-conf':
    ensure => 'directory',

  # a fuller example, including permissions and ownership
  file { '/var/log/admin-app-log':
    ensure => 'directory',
    owner  => 'root',
    group  => 'wheel',
    mode   => '0750',

  # this example is incorrect and creates a file
  file { '/etc/site-conf/':
    ensure => 'present',


Creating a directory is another task that is handled by the powerful and flexible file type. In this case specifying a directory is done by setting ensure to (unsurprisingly) directory. The third example is a (semi-)common mistake made by people coming from certain other tools. Adding a / to the end of a file name isn't enough to tell puppet to make a directory, so it creates a file instead, and silently drops the / off the end of the name.

You can use a number of parameters from the file type to control the directories properties, such as the owner, group and mode (permissions).

It's also worth noting that puppet will not create missing parent directories. There is a long standing bug regarding this feature request "Directory creation fails if parent directory does not exist" and while there are a couple of workarounds there's no official fix.

See also