Chef infra chef中的组资源不是幂等的
作为某些要求的一部分,我被要求创建两个具有特定GID的组“group1”和“group2”。以及具有特定UID的“user1”用户。 我在属性中将组的名称及其ID指定为哈希,如下所示:Chef infra chef中的组资源不是幂等的,chef-infra,Chef Infra,作为某些要求的一部分,我被要求创建两个具有特定GID的组“group1”和“group2”。以及具有特定UID的“user1”用户。 我在属性中将组的名称及其ID指定为哈希,如下所示: default['abc']['groups'] = {'group1' => 45xxx, 'group2' => 45xxx} 我在我的食谱中这样称呼它。我在这里要做的是首先创建两个组。然后创建用户。然后修改组以添加用户 #Create Groups node['abc']['groups'].
default['abc']['groups'] = {'group1' => 45xxx, 'group2' => 45xxx}
我在我的食谱中这样称呼它。我在这里要做的是首先创建两个组。然后创建用户。然后修改组以添加用户
#Create Groups
node['abc']['groups'].each_key do |group|
group group do
gid node['abc']['groups'][group]
end
end
# Create the user.
user 'user1' do
uid 45xxx
end
# Configure the user.
# Make it a member of the appropriate supplementary groups, and
# ensure its environment will be set up properly upon login.
node['abc']['groups'].each_key do |grp|
group grp do
members ['user1']
append true
action :modify
end
end
它在第一次运行时运行良好。然后,当我再次运行它时,会发生以下情况:
Recipe: abc::recipename
* group[group1] action create
- alter group group1
- replace group members with new list of members
* group[group2] action create
- alter group group2
- replace group members with new list of members
* user[user1] action create (up to date)
* group[group1] action modify
- modify group group1
- add missing member(s): user1
* group[group2] action modify
- modify group group2
- add missing member(s): user1
它所做的是,当它遇到第一个块时重新运行,它会改变组以删除所有用户。在第二个块中,它再次修改组以添加用户。
现在,第一个组块仅用于创建组。如果该组已经存在,那么为什么它要修改它,即使我们在第一块中没有提到任何关于成员的内容?它应该把它看作是最新的,然后继续前进。请帮助我理解它为什么会这样。我无法理解此处是否缺少某些内容
成员
默认为[]
,因此,如果不指定它,您就告诉它将成员设置为空。如果您在第一个组资源上设置append true
和members[]
,它将使它不会尝试管理我认为您需要的成员列表。Chef通常在对象级建模方面进行操作,并且您正试图以更程序化的方式使用它,所以事情看起来有点奇怪