Skip to content

Commit

Permalink
Override autogenerated file path with variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Cabezas committed Sep 11, 2023
1 parent 6d210df commit 7076a2f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,31 @@
Sensitive[String] $password,
Optional[String] $group = $user,
Optional[String] $filename = '.netrc',
Optional[Stdlib::Absolutepath] $file_path = undef,
) {
$file_path = $user ? {
$user_file = $user ? {
'root' => "/root/${filename}",
default => "/home/${user}/${filename}",
}
if !defined(Concat[$file_path]) {
concat { $file_path:
$real_file_path = $file_path ? {
undef => $user_file,
default => $file_path,
}
if !defined(Concat[$real_file_path]) {
concat { $real_file_path:
ensure => present,
mode => '0600',
owner => $user,
group => $group,
ensure_newline => true,
}
concat::fragment { "${file_path}-header":
target => $file_path,
concat::fragment { "${real_file_path}-header":
target => $real_file_path,
content => '# File content managed by Puppet',
}
}
concat::fragment { "${user}-${machine}-${login}":
target => $file_path,
target => $real_file_path,
content => Sensitive(epp('netrc/netrc.epp',
{
machine => $machine,
Expand Down

0 comments on commit 7076a2f

Please sign in to comment.