大网数据广告活动
服务器运维问答

Best way for user management with Hiera

· 52CE 我爱测

I am currently trying to move our Puppet setup to further use Hiera. In regard to this, I would like to create the users with Hiera, but having some problems how to do this when moving up in the hierarchy. The scenario is that I …

问题原文

原帖链接 · Hellstorm · CC BY-SA 3.0

I am currently trying to move our Puppet setup to further use Hiera. In regard to this, I would like to create the users with Hiera, but having some problems how to do this when moving up in the hierarchy.

The scenario is that I want to have a set of base users which are included in every installation. Also, I sometimes need to add some specific users only for a different subset of nodes, maybe specific to some datacenters or to some nodes.

So I thought about the following setup:

hiera.yaml:

:hierarchy:
  - "nodes/%{::trusted.certname}"
  - "datacenter/${::datacenter}"
  - "common"

users.pp:

class profile::users {
  $user_accounts = hiera('user_accounts')
  create_resources(user, $user_accounts)
}

and in common.yaml:

user_accounts:
  bob:
    comment: "Bob"
    managehome: true

and then go up the hierarchy. The main problems I see with this is:

  • How do I implement default attributes for each user? For example, in this example, I want to set managehome: true for all users, and not explicitly write it every time. I maybe want to disable it sometimes, though.
  • If I have user_accounts further up in the hierarchy, it would overwrite the user_accounts hash from common.yaml, so that I would need to duplicate the entries. I stumbled across the deep merging in Hiera, but wonder if this is actually used or is best practice. Also, it would not solve the first problem, and I need to set merge_behavior in hiera.yaml, which I want to avoid.
  • How could I insert ssh keys for every user here? The nicest solution would be to just add the ssh keys as an attribute to the user account.

So, does anyone have an insight how user management is actually nicely done with Puppet? Thanks :)

已采纳解答

原帖链接 · womble · CC BY-SA 3.0

Implement default attributes for each user in the type definition:

define user($managehome = true) { ... }

Yes, you need to use merging, but rather than specifying it in the hiera data, use the hiera_array function to do the lookup for the data you want.

SSH keys are just another attribute in the data set, which your user type should set appropriately on the system.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-07-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。