Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove Puppet user which has running processes
define your_class::user (
$user = $name,
$ensure = 'present',
){
# only call when user gets removed
if $ensure == 'absent' {
exec {
"killing ${user}":
command => "pkill -9 -u ${user}",
# need to check if user exists and processes are running
# otherwise command would fail with no processes
onlyif => "grep '^${user}' /etc/passwd && ps -u ${user}",
# run before user gets removed
before => User[$user];
}
}
# create/remove user with managed home
user {
$user:
ensure => $ensure,
home => "/home/${user}",
managehome => true,
shell => '/bin/bash',
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment