0

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?

1 Answer 1

1

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 ;)

4
  • Is that the only spelling for that Irish name? Mar 18, 2014 at 13:24
  • O/T, but yes, it's the accepted spelling of the Gaelic name, often missing the accent on the 'e': en.wikipedia.org/wiki/S%C3%A9amus Mar 18, 2014 at 13:26
  • 1
    Starting with Puppet 2.7 you don't need to set the require since it will auto-require all parent nodes (projects.puppetlabs.com/issues/6368)
    – faker
    Mar 18, 2014 at 13:32
  • @faker - thanks, valid point :) However I always tend to err on the side of caution and verboseness, if anything to make it clearer if files are spread across multiple modules/subclasses. Mar 18, 2014 at 13:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .