Forge Home

filepath

Recursively manage directory paths natively

20,398 downloads

1,327 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 1.1.0 (latest)
  • 1.0.1
  • 1.0.0
released Mar 3rd 2023
This version is compatible with:
  • Puppet Enterprise 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2017.1.x, 2016.5.x, 2016.4.x
  • Puppet >= 4.7.0 < 8.0.0
  • , , , , , , , , ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'edgej-filepath', '1.1.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add edgej-filepath
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install edgej-filepath --version 1.1.0

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

edgej/filepath — version 1.1.0 Mar 3rd 2023

filepath

Build Status Latest Tag PDK Version Puppet Forge

Puppet type to create and manage recursive filepaths without resorting to needless hackery.

Table of Contents

  1. Description
  2. Setup - The basics of getting started with filepath
  3. Usage - Configuration options and additional functionality
  4. Limitations - OS compatibility, etc.
  5. Development - Guide for contributing to the module

Description

The Puppet filepath module adds the filepath resource that can be used to recursively create a directory tree.

One of the significant limitations to Puppet's file resource is that it does not create parent directories, so specifying a path where the parent directory doesn't yet exist on the filesystem will cause an error at execution time (while typically passing any spec tests).

The filepath resource eliminates the common need for hacks and workarounds to ensure that parent directories exist for a file resource to be created.

For example:

exec { 'parent dir':
   command => "mkdir -p ${directory}",
   creates => $directory,
}

Like the built-in file resource, filepath can manage the owner, group, and permissions of the directory. Using the managedepth parameter, you may specify how many levels down to set ownership and permissions, starting from the deepest directory.

For example, setting /path/to/some/dir with managedepth => 2 will result in the creation of the directories path and to with the default user (root) and permissions and the directories some and dir being created with the specified ownership and permissions.

The filepath resource does not manage the contents of the directory, it only creates the directories, similar to running mkdir -p at the shell.

Setup

Beginning with filepath

No additional setup needed after installing the module. Via pluginsync, the type will be available to all catalogs and nodes.

Usage

A simple example:

filepath { '/path/to/nested/directory':
  ensure      => present,
  owner       => 'foo',
  group       => 'bar',
  mode        => '0774',
  managedepth => 2,
}

Or, with managing a file within the nested directory tree:

filepath { '/opt/puppetlabs/bin':
  ensure      => present,
  owner       => 'foo',
  group       => 'bar',
  mode        => '0774',
  managedepth => 2,
}

file { '/opt/puppetlabs/bin/moog':
   ensure => present,
   owner  => 'foo',
   group  => 'bar',
   mode   => '0770'.
   source => 'puppet:///modules/role/moog',
   require => Filepath['/opt/puppetlabs/bin'],
}

To remove a filepath, specify the path to be removed and use managedepth to control how many levels of the directory tree are removed.

$ ls /path/to/
deleted

$ ls /path/to/deleted
dir
filepath { '/path/to/deleted/dir':
  ensure => absent,
  managedepth => 2,
}
$ ls /path/to

$ ls /path/to/deleted
ls: /path/to/deleted: No such file or directory

And that's it! Very simple and without resorting to hacks to get the job done.

Limitations

Currently no support for non-posix operatingsystems (that means you, Windows!)

The filepath resource does not manage files or contents of any directories, only creation or deletion of the path itself. Use the built-in file resource to set or remove any file or directory content.

Tested on Centos 7 and Ubuntu 14.04.

Development

The module is largely developed with the Puppet Development Kit (pdk) and can be validated and tested with that tool. The exception is Beaker tests, which require installation with Bundler for the gems and execution via rake beaker.

To submit a change to the module:

  • Fork the repo.
  • Make any necessary changes and validate syntax with pdk validate.
  • Add any unit tests for any additional features.
  • If applicable, add additional acceptance tests.
  • Ensure all tests are passing with pdk test unit or rake spec.
  • Submit a PR.