Skip to content

Instantly share code, notes, and snippets.

@thonixx
Created March 24, 2015 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thonixx/2ea77dbb4c76df053f59 to your computer and use it in GitHub Desktop.
Save thonixx/2ea77dbb4c76df053f59 to your computer and use it in GitHub Desktop.
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