Last active
July 11, 2017 18:47
-
-
Save DracoBlue/9870435 to your computer and use it in GitHub Desktop.
Small snippet to define a bash-exec type for puppet, which launches the exec with `--login` to provide a login shell (full PATH and sourced bash files).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define bash_exec ( | |
$command = $name, | |
$user, | |
$creates = undef, | |
$cwd = undef, | |
$environment = undef, | |
$group = undef, | |
$logoutput = undef, | |
$onlyif = undef, | |
$path = undef, | |
$provider = "posix", | |
$refresh = undef, | |
$refreshonly = undef, | |
$returns = undef, | |
$timeout = undef, | |
$tries = undef, | |
$try_sleep = undef, | |
$umask = undef, | |
$unless = undef | |
) { | |
$escaped_command = regsubst($command, "\"", "\\\"", 'G') | |
if $unless == undef { | |
$escaped_unless = undef | |
} else { | |
$unless_with_escaped_quotes = regsubst($unless, "\"", "\\\"", 'G') | |
$escaped_unless = "/bin/su -l ${user} -c \"/bin/bash --login -c \\\"${unless_with_escaped_quotes}\\\"\"" | |
} | |
if $onlyif == undef { | |
$escaped_onlyif = undef | |
} else { | |
$onlyif_with_escaped_quotes = regsubst($onlyif, "\"", "\\\"", 'G') | |
$escaped_onlyif = "/bin/su -l ${user} -c \"/bin/bash --login -c \\\"${onlyif_with_escaped_quotes}\\\"\"" | |
} | |
exec { $name: | |
command => "/bin/su -l ${user} -c \"/bin/bash --login -c \\\"${escaped_command}\\\"\"", | |
creates => $creates, | |
cwd => $cwd, | |
environment => $environment, | |
group => $group, | |
logoutput => $logoutput, | |
onlyif => $escaped_onlyif, | |
path => $path, | |
provider => $provider, | |
refresh => $refresh, | |
refreshonly => $refreshonly, | |
returns => $returns, | |
timeout => $timeout, | |
tries => $tries, | |
try_sleep => $try_sleep, | |
umask => $umask, | |
unless => $escaped_unless | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment