Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

recursively make directory tree in puppet without purging

Tags:

puppet

I want to create the directory structure /var/www/apps/example/current/public if it doesn't exist using puppet. If it already exists I don't want to purge the contents of the directories. How do I do this? Below is what I have so far:

file { "/var/www/apps/example/current/public":
  owner => 'deploy',
  group => 'users',
  ensure => "directory",
  purge => false,
  recurse => true
}

This gives me

 Cannot create /var/www/apps/example/current/public; parent directory /var/www/apps/example/current does not exist
like image 998
Kyle Decot Avatar asked Oct 17 '14 20:10

Kyle Decot


1 Answers

The recurse parameter does not allow you to create parent directories. It is used to enforce property values such as owner, mode etc. on directory contents and subdirectories recursively.

file { '/var/www':
    owner   => 'www-data',
    recurse => true,
}

As a matter of fact, Puppet currently cannot automatically create all parent directories. You should add all relevant directories as resources instead.

file { [ '/var/www/apps',
         '/var/www/apps/example',
         '/var/www/apps/example/current',
         '/var/www/apps/example/current/public', ]:
           ensure => directory,
           ...
}

Existing content will remain unmolested. There is no need to pass the purge parameter.

like image 117
Felix Frank Avatar answered Oct 04 '22 22:10

Felix Frank