Puppet recurse attribute for file resource when creating non-directory/normal files

puppet

If I want:

file { '/var/shennanigans/happy-hour.drunk':
    ensure => present,
    mode => 700,
    owner => shamus
}

Can I use recurse => true to ensure the shennanigans directory exists or do I need to create a separate resource with an ensure => directory?

Best Answer

You'll need to declare two file resources, one for the directory, and one for the file, using dependencies to ensure that the file isn't placed before the directory has been created, like so:

file { '/var/shennanigans':
  ensure  => directory,
  purge   => true,
  recurse => true,
  owner   => 'seamus',
}

file { '/var/shennanigans/happy-hour.drunk':
  ensure  => present,
  mode    => 0700,
  owner   => 'seamus',
  require => File['/var/shennanigans'],
}

Note that the mode parameter should use a four-digit octal notation rather than three-digits - see Puppet Type docs.

Btw I've corrected your owner's name ;)

Related Topic