# creating public_html for every user

I want to ensure that public_html directory is present for every user.

The catch is that I dont want to specify the users, for I might not know the names of them.

I use the following syntax. Is there something I could use in the user slot so that it would check what users exist and give them the directory

file { '/home/user/public_html':
ensure => 'directory',
}

edit retag close merge delete

Sort by » oldest newest most voted

Puppet doesn't work well for managing things that you cannot list. If you can get a list of users into your manifest then it is easy to set up the directories. For example:

class profile::public_html (
Array[String] $users, ) {$users.each |$user| { file { "/home/${user}/public_html":
ensure => directory,
}
}
}


So somehow you need to feed a list of users into your manifest. There are two ways you could go about doing this.

1) You could manually manage the users by specifying them in Hiera, so that each server then knows what users it should have. Hiera will automatically populate the parameter in the above manifest if the value in Hiera is correctly named. This is generally what I'd recommend doing in the long-term since it gives you greater control over the configuration.

2) You could write a custom fact or an executable fact to list the users that you care about on the target system. Likely you could read them out of /etc/passwd or /etc/group and then narrow them by group membership so that you don't end up adding public_html directories for e.g. the puppet user. Then you could directly reference this fact in the manifest and loop over the users in it.

more