Chef 用户资源(检查是否存在?)
Chef Users resource (check if exists?)
我知道如何创建用户资源:
user "random" do
supports :manage_home => true
comment "Random User"
uid 1234
gid "users"
home "/home/random"
shell "/bin/bash"
password "$JJsvHslV$szsCjVEroftprNn4JHtDi."
end
但我不确定如何使用 Chef 查找当前节点上所有用户的列表。我查看了在 chef-client 运行 期间检查 node[:users],但只有 node[:current_user] 对我可用。有没有办法在 Chef 食谱中询问普通用户是否存在?
我处于不应该t/can创建用户的情况(由于公司规定,但我绝对不应该继续安装我的说明书中定义的其他东西,除非 xyz 用户已经存在。)
Ohai为您查询本系统用户:
if node['etc']['passwd']['random']
# Do deploy
end
这仅适用于本地帐户,但如果帐户由 LDAP 或 AD 管理,则上述内容不成立。我建议使用:
"getent group #{mygroup}"
"getent passwd #{myuser}"
在 ruby 块中。
这不起作用,如果帐户不是本地的:
if node['etc']['passwd']['random']
# Do deploy
end
我的 nsswitch.conf 中有 "passwd: files sss",因为帐户在 IPA 中。
我想只有 SorinS 的解决方案有效。
我收到与 undefined method '[]' for nil:NilClass
相同的错误消息 Tom Klino. I suspect that those having trouble with coderanger's 解决方案已禁用 passwd Ohai 插件。
对于我们这些拥有大型目录环境的人来说,在 client.rb
中禁用 passwd 插件以避免在客户端报告运行时出现 413 错误 ("Request Entity Too Large") 是很常见的。检查 /etc/chef/client.rb
是否:
ohai.disabled_plugins [:Passwd]
禁用此插件后,node['etc']['passwd']
对您的食谱来说是 ,因此会出现错误。在我的环境中,重新启用插件可以修复此错误。
我知道如何创建用户资源:
user "random" do
supports :manage_home => true
comment "Random User"
uid 1234
gid "users"
home "/home/random"
shell "/bin/bash"
password "$JJsvHslV$szsCjVEroftprNn4JHtDi."
end
但我不确定如何使用 Chef 查找当前节点上所有用户的列表。我查看了在 chef-client 运行 期间检查 node[:users],但只有 node[:current_user] 对我可用。有没有办法在 Chef 食谱中询问普通用户是否存在?
我处于不应该t/can创建用户的情况(由于公司规定,但我绝对不应该继续安装我的说明书中定义的其他东西,除非 xyz 用户已经存在。)
Ohai为您查询本系统用户:
if node['etc']['passwd']['random']
# Do deploy
end
这仅适用于本地帐户,但如果帐户由 LDAP 或 AD 管理,则上述内容不成立。我建议使用:
"getent group #{mygroup}"
"getent passwd #{myuser}"
在 ruby 块中。
这不起作用,如果帐户不是本地的:
if node['etc']['passwd']['random']
# Do deploy
end
我的 nsswitch.conf 中有 "passwd: files sss",因为帐户在 IPA 中。 我想只有 SorinS 的解决方案有效。
我收到与 undefined method '[]' for nil:NilClass
相同的错误消息 Tom Klino. I suspect that those having trouble with coderanger's 解决方案已禁用 passwd Ohai 插件。
对于我们这些拥有大型目录环境的人来说,在 client.rb
中禁用 passwd 插件以避免在客户端报告运行时出现 413 错误 ("Request Entity Too Large") 是很常见的。检查 /etc/chef/client.rb
是否:
ohai.disabled_plugins [:Passwd]
禁用此插件后,node['etc']['passwd']
对您的食谱来说是