Trying to delete home directory while deleting accounts.

97 views
Skip to first unread message

eduardo

unread,
Oct 5, 2012, 1:40:00 PM10/5/12
to Puppet Users
Hi all,
I wondering why having provider=useradd the parameter managehome =>
true don't delete home directory ?
I have :
user { $name: ensure => absent, managehome => true }
As result, home directory was not deleted.

I appreciate any advise about it.
Thanks in advanced, eduardo

jcbollinger

unread,
Oct 8, 2012, 9:56:33 AM10/8/12
to puppet...@googlegroups.com


It is reasonably common to want to create home directories automatically when creating a user account, but at least as common to want to avoid removing them when removing a user.  I see that the type reference appears to suggest that "managehome => true" would produce both behaviors, but that is not consistent with historic Puppet behavior, which is to provide only homedir creation, not removal.  I don't know whether the docs are misleading, whether Puppet is buggy in this regard, or whether you're using a different version than is described by the current docs.

If you want to work around this issue, you can wrap your User declarations in a defined type that provides the desired behavior.  A minimalistic version might look something like this:

modules/user/manifests/hosted_user.pp:
----------------------------------------------------------
define user::hosted_user ($ensure = 'present') {
  $homedir = "/home/${name}"

  user { "${name}":
    ensure => "${ensure}",
    home => "${homedir}",
    managehome => true
  }

  if "${ensure}" == 'absent' {
    file { "${homedir}":
      ensure => absent,
      recurse => true,
      require => User["${name}"]
    }
  }
}
------

You could then use it like so:

user::hosted_user { 'eduardo': ensure => absent }

For real-world use you would probably want additional parameters, etc.


John

Reply all
Reply to author
Forward
0 new messages