【发布时间】:2015-07-07 12:13:23
【问题描述】:
我正在通过 Chef 创建一个用户。他的属性存储在数据包中:
{
"id": "developer",
"home": "/home/developer",
"shell": "/bin/zsh",
"password": "s3cr3t"
}
配方是:
developer = data_bag_item('users', 'developer')
user developer['id'] do
action :create
supports :manage_home => true
home developer['home']
comment developer['comment']
shell developer['shell']
password developer['password']
end
问题是如果节点上没有安装zsh,我就不能以developer 登录。所以,我想有条件地为user 资源应用参数,例如:
user developer['id'] do
action :create
supports :manage_home => true
home developer['home']
comment developer['comment']
if installed?(developer['shell'])
shell developer['shell']
end
password developer['password']
end
我怎样才能做到这一点?
【问题讨论】:
-
安装 zsh 与包资源不是一个选项吗?
-
@Tensibai,好吧,实际上我使用那本食谱安装了
zsh。我只是不想过分依赖它。 -
在这种情况下,@mudasobwa 的答案是正确的(如果答案包括关于 ruby 代码如何为未来读者工作的小解释,我会投赞成票)
-
@MarkO'Connor,我不是 Ruby / Chef 方面的专家,但看起来像
opscode/usershas the same problem:如果指定的 shell 不存在,则用户已“损坏”。 -
@Tensibai,我刚刚对其进行了测试,如果您在一次厨师运行期间运行
zsh配方和我的问题中的配方,它实际上不起作用。 Looks like in this caseFile.exist? developer['shell']evaluates to false,然后安装zsh,然后运行我的配方。我正在尝试解决这个问题,并将评论@mudasobwa 的答案。
标签: ruby chef-infra chef-recipe