Extended file resource

Reinhard Vicinus



6,391 latest version

4.4 quality score

Version information

  • 1.0.9 (latest)
  • 1.0.1
released May 21st 2016
This version is compatible with:
  • RedHat

Start using this module

Tags: file


vicinus/exfile — version 1.0.9 May 21st 2016



The exfile module defines an extended file resource which supports filenames which are relative to a base directory. Also parent directories can be automatically created (with some limitations). Content can be created via templates and path and target parameters can contain special variables, that are expanded during resource creation.


The exfile resource can be used like the file resource. To define a file relative to configured base directory, use the basedir parameter.

    exfile { 'test.txt':
      basedir => '/tmp',

This will create the file /tmp/test.txt. It's also possible to create with the path parameter. The following will also create /tmp/test.txt.

    exfile { 'testfile':
      path    => 'test.txt',
      basedir => '/tmp',

###create_parent_dirs examples

create_parent_dirs ensures, that file resources with ensure directory for every directory between basedir (or '/' if basedir is not set) and the location of the exfile are created.

    exfile { 'a/b/1.txt':
      basedir => '/tmp',
      create_parent_dirs => true,
    exfile { 'a/b/2.txt':
      basedir => '/tmp',
      create_parent_dirs => true,

The example above will create file resources for the directories /tmp/a and /tmp/b but not for /tmp. The parameters owner, group and mode if set at the exfile resource are also used for the directory file resources. Puppet will automatically add the x modifier to the mode parameter of directories. ensure_resource is used, so that not multiple file resources for the same directory are created. Therefore the limitations of ensure_resource apply (all parameters must be identical). Also an error applying the created catalog will ocour, if some directory in the list of automatically created directories is actually a link to another directory.

###content_type examples

The content_type can be used to format the provided content.

    exfile { '/tmp/test.txt':
      content_type => 'erb',
      content_template => 'exfile/hashofkeyvalue.erb',
      content => { 'key1' => 'value1', 'key2' => 'value2', },

The above example will create a file with content

  key1 = value1
  key2 = value2