Files and paths on Windows

This version is out of date. For current versions, see Puppet packages and versions.

Puppet and Windows handle directory separators and line endings in files somewhat differently, so you must be aware of the differences when you are writing manifests to manage Windows systems.

Directory separators in file paths

Several resource types (including file, exec, and package) take file paths as values for various attributes. The Puppet language uses the backslash (\) as an escape character in quoted strings. However, Windows also uses the backslash to separate directories in file paths, such as C:\Program Files\PuppetLabs. Additionally, Windows file system APIs accept both backslashes and forward slashes in file paths, but some Windows programs accept only backslashes.

Generally, if Puppet itself is interpreting the file path, or if the file path is meant for the master, use forward slashes. If the file path is being passed directly to a Windows program, use backslashes. The following table lists common directory path uses and what kind of slashes are required by each.
File path usage Slash type
Template paths, such as template('my_module/content.erb'). Forward slash (/)
puppet:/// URLs. Forward slash (/)
The path attribute or title of a file resource. Forward slash (/) or backslash (\)
The source attribute of a package resource. Forward slash (/) or backslash (\)
Local paths in a file resource's source attribute. Forward slash (/) or backslash (\)
The command of an exec resource. However, some executables, such as cmd.exe, require backslashes. Forward slash (/) or backslash (\)
Any file paths included in the command of a scheduled_task resource. Backslash (\)
Any file paths included in the install_options of a package resource. Backslash (\)
Any file paths used for Windows PowerShell DSC resources. For these resources, single quote strings whenever possible. Backslash (\)

Line endings in files

Windows uses CRLF line endings instead of *nix's LF line endings. Be aware of the following issues:
  • If you specify the contents of a file with the content attribute, Puppet writes the content in binary mode. To create files with CRLF line endings, specify the \r\n escape sequence as part of the content.

  • When downloading a file to a Windows node with the source attribute, Puppet transfers the file in binary mode, leaving the original newlines untouched.

  • If you are using version control, such as Git, ensure that it is configured to use CRLF line endings.
  • Non-file resource types that make partial edits to a system file, such as the host resource type, which manages the %windir%\system32\drivers\etc\hosts file, manage their files in text mode and automatically translate between Windows and *nix line endings.
    Note: When writing your own resource types, you can get this behavior by using the flat file type.
Puppet sites use proprietary and third-party cookies. By using our sites, you agree to our cookie policy.