There isn't a GUI way of doing it, though you could assign config groups to a host group and assign multiple hosts to that via the host list (Hosts > All hosts, tickboxes, Select Action > Change Group).
You're right in that we're missing config group support in the CLI too, which surprised me. I've filed #7520 to fix that.
Probably the best way for now is via the REST API. Here's an example to update just the one host, but obviously you can put this in a simple shell loop and do much more with it.
(I like to pipe the curl output through json_reformat, very handy if you have it installed.)
First you may want to get a list of config groups, or do it via the GUI:
$ curl -k -u admin:password https://localhost/api/v2/config_groups
Now you can fetch an individual host and see which config groups are already assigned:
$ curl -k -u admin:password https://localhost/api/v2/hosts/foreman.example.com
...
"config_groups": [
]
So nothing's there right now.
Here I update the host's associated config groups with an array of names ("test" in this instance):
$ 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": [
]
}
]
You can also use IDs:
{"host":{"config_group_ids":[2, 3, 5, 7]}}
So putting that together you could do something like:
for h in a.example.com b.example.com c.example.com; do
curl -k -u admin:password -H 'Content-Type: application/json' -X PUT \
-d '{"host":{"config_group_names":["Base", "Web server"]}}' \
https://localhost/api/v2/hosts/${h}
done
I assume you use the foreman WebGui:
If you are in the Smart Class Parameter
tab of the ntp class, select servers
, check the Override
Box an then select array
for Parameter type
. Then input the list of your desired timeserver in the following form:
["timehost1.domain.tld","timehost2", ...]
It took me a while myself to figure that out.
In general, you need to know or find out which type is expected from the puppet module. I find myself looking into the code of the modules if it is not clear in the first place. Also, if you want to make a parameter over writable somewhere down the road of host groups or whatever you use for node of different types, I found that you have to set the default yourself. The builtin default only works while Override
is unchecked. At least for modules like ntp which have a params subclass. Otherwise you end up with errors stating the parameter was not found/could not be set or similar.
I'm fairly new to puppet myself, so if anyone has a better explanation I'd be glad.
Cheers, Christoph
Screenshot
Best Answer
You want
GET /api/v2/hosts
(API doc) to retrieve a list of hosts, then add thesearch
parameter to filter the result.Use
search=params.foo=bar
to filter for thefoo
parameter. You can find other search strings through the UI search autocomplete (it's exactly the same syntax) and more information's in Foreman manual: Searching.So, the full URL to query would be something like: