The local files

...and how to work with them.

Posted on July 26, 2017

The local files

An article by Dominique, our head of technology.


Cdist is located on github.

A small overview of cdist you can find in our article about basic cdist usage and in other previous cdist blog posts:
cdist types and parameters
The object ID and singleton types
The gencode scripts

There are different man pages available for using local files:


Local files are often very useful, because it's possible to simply copy local file to a server without having the config directly in the manifest.

For example it is very simple to have the ssh-keys locally available in form of files and then manage the authorized_keys remotely.

Local files for each type

Each type is able to organize local files. To use local files, simply create the directory files in the type directory.

mkdir $HOME/.cdist/type/__TYPE_NAME/files

After that, the type can refer to a file in the files directory via the $__type/files/<FILENAME> variable.

For example:

__file /tmp/testfile --mode 0644 --source "$__type/files/testfile" 

This would create the file /tmp/testfile. The content of the /tmp/testfile would be the same as in the locally available files/testfile.

Basically it is possible to refer to the local files with all types which use a
--source parameter.

Global files

Besides the files which are only available for each type. It is possible to have global files directory so all types available are able to refer to files in this directory.

This may be useful if different types need to refer to the same files.

For this purpose the directory files needs to be created directly in the
dot-cdist main directory.

mkdir $HOME/.cdist/files

The reference is done with the $__files/<FILENAME> variable.

For example:

__file /tmp/testfile --mode 0644 --source "$__files/testfile" 

Like above, this would create the file /tmp/testfile but this time fill it with the content from $__files/testfile.

Also like above xit is possible to refer to the local files with all types which use a --source parameter.

Temporary files

A type may use temporary files probably to preprocess before sending them to the remote host. The temporary directory is mostly used for templating.

For this purpose it is possible to create a temporary directory which will be removed after cdist ended.

To use a temporary files directory simply write this in your manifest:

mkdir "$__object/files" 

Then it is possible to refer to files in this temporary directory.

Keep in mind that the $__object/files differs from the $__type/files or the $__files directory.

More information

If you have trouble or need more information, visit our github page.
If you have questions or feedback just write us via Mail or check out our chat.