工头将多个主机分配给一个configuration组

工头1.6.0上,可以轻松地将多个主机分配给一个configuration组(在Configure-> Puppet-> Config Groups菜单下)?

我已经有了一个相当不错的Web界面和锤子cli,但似乎无法find任何东西。

虽然您可以将configuration组分配给主机组,并通过主机列表(主机>所有主机,checkbox,select操作>更改组)分配多个主机,但是没有这样做的GUI方式。

你说得对,因为我们在CLI里也缺lessconfiguration组的支持,这让我很吃惊。 我已经提交#7520来解决这个问题。

现在最好的方法可能是通过REST API。 下面是一个例子来更新一个主机,但是显然你可以把它放在一个简单的shell循环中,并且用它来做更多的事情。

(我喜欢通过json_reformat来pipe理curl输出,如果已经安装了它,非常方便。)

首先,您可能需要获取configuration组的列表,或通过GUI进行configuration:

$ curl -k -u admin:password https://localhost/api/v2/config_groups 

现在您可以获取单个主机并查看哪些configuration组已被分配:

 $ curl -k -u admin:password https://localhost/api/v2/hosts/foreman.example.com ... "config_groups": [ ] 

所以没有现在。

在这里,我使用一个名称数组更新主机的关联configuration组(在这个例子中是“test”):

 $ curl -k -u admin:password -H 'Content-Type: application/json' -d '{"host":{"config_group_names":["test"]}}' -X PUT https://localhost/api/v2/hosts/foreman.example.com $ curl -k -u admin:password https://localhost/api/v2/hosts/foreman.example.com ... "config_groups": [ { "id": 1, "name": "test", "created_at": "2014-09-18T10:34:58Z", "updated_at": "2014-09-18T10:52:39Z", "puppetclasses": [ ] } ] 

您也可以使用ID:

 {"host":{"config_group_ids":[2, 3, 5, 7]}} 

所以把它们放在一起你可以做一些事情:

为h在a.example.com b.example.com c.example.com; 做
   curl -k -u admin:password -H'Content-Type:application / json'-X PUT \
     -d'{“host”:{“config_group_names”:[“Base”,“Web server”]}''\
     https://开头本地主机/ API / V2 /主机/ $ {H}
 DONE