Ask Your Question
0

creating public_html for every user

asked 2017-05-12 03:27:36 -0500

kuulas gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-05-13 13:35:07 -0500

smarlow gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-05-12 03:27:36 -0500

Seen: 20 times

Last updated: May 13