Handling multiline with HEREDOC
Writing multiline file fragments in Puppet mostly resulted in code that was hard to read, mostly due to indentation. With Puppet 4, the heredoc
style was added. It is now possible to specify a heredoc
tag and marker:
$motd_content = @(EOF) This system is managed by Puppet local changes will be overwritten by next Puppet run. EOF
The heredoc
tag starts with an @
sign followed by arbitrary string enclosed in parenthesis. The heredoc
marker is the string given in the tag.
If variables are required inside the heredoc
document, the variable interpolation can be enabled by putting the tag string in double quotes. Variables inside the heredoc
are written like Puppet DSL variables: a dollar sign followed by the scope and the variable name:
$motd_content = @("EOF") Welcome to ${::fqdn}. This system is managed by Puppet version ${::puppetversion}. Local changes will be overwritten by the next Puppet run EOF
Normally, heredoc
does not handle escape sequences. Escape...