Created
March 24, 2015 11:44
-
-
Save thonixx/2ea77dbb4c76df053f59 to your computer and use it in GitHub Desktop.
Remove Puppet user which has running processes
This file contains hidden or 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 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