0

On foreman 1.6.0 is it possible to easily assign multiple hosts to a config group (Under the Configure->Puppet->Config Groups menu)?

I've had a pretty good look around the web interface and hammer cli but can't seem to find anything.

1 Answer 1

1

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
4
  • Awesome! hope to see this feature in a later version. Thank!
    – glisignoli
    Sep 20, 2014 at 14:07
  • Ok so one thing that I seem to have found which is a bit of a downer, I have to pull each host in a loop to check for a config group, there doesn't seem to be a json way to pull a list of what hosts belong to the config groups :(
    – glisignoli
    Sep 24, 2014 at 3:21
  • It's possible to search for hosts with a particular config group: localhost/api/v2/hosts?search=config_group=Base (any search you can do in the UI search boxes will work in the API) Sep 24, 2014 at 7:30
  • Oh wow! Your some sort of wizard aren't you! That's perfect!
    – glisignoli
    Sep 24, 2014 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .