Hammer os set-default-template

Problem:

In version 1.23 i am able to set the default template for a OS using
hammer os set-default-template --id <OS_ID> --config-template-id <TEMPLATE_ID>

In version 2.0 the help changed.

Usage:
    hammer os set-default-template [OPTIONS]

Options:
 --id OS ID                        Operatingsystem id
 --provisioning-template-id TPL ID Provisioning template id to be set
 -h, --help                        Print help

I would expect the command to be
hammer os set-default-template --id <OS_ID> --provisioning-template-id <TEMPLATE_ID>

But when i try this ill get

$ hammer os set-default-template --id 2 --provisioning-template-id 122
Could not set the os default template:
  Template kind can't be blank

There is nothing in the help about the template kind OS i don’t understand this error.

I believe that the provisioning template you are trying to assign to the os does not have a “kind” field - e.g. “PXE template”, “Finish template” etc. When trying to assign it to the OS, the saving failing due to the template being invalid. To correct this, you need to set the correct kind for the template itself before assigning it.

Yesterday i set the default template in the UI by editing the OS. Now i did the same command as yesterday and it seems to work.

$ hammer os set-default-template --id 2 --provisioning-template-id 122
[aaa_winpe_finish] was set as default finish template.

So the system does not need the information or has it somewhere where hammer does not look. If u want i can help track the cause of it (the templates are from 1.23 version) using git. Else ill just export the new ones and see if they work now.

I reinstalled foreman with the script i used before. The above command errors now.

$ hammer template list
----|--------------------------------------|-----------
ID  | NAME                                 | TYPE
----|--------------------------------------|-----------
133 | aaa_ipxe_win                         | iPXE
139 | aaa_ipxe_windows                     | PXELinux
140 | aaa_pxe_linux_winpe                  | PXELinux
142 | aaa_pxe_windows                      | PXELinux
124 | aaa_wim_install.bat                  | user_data
131 | aaa_win7_unattend_template           | script
148 | aaa_win_driver_snippet               | snippet
144 | aaa_winpe_driver_post                | snippet
122 | aaa_winpe_finish                     | finish
hammer os list
---|------------------------------------------|--------------|--------
ID | TITLE                                    | RELEASE NAME | FAMILY
---|------------------------------------------|--------------|--------
1  | Ubuntu 18.04.4 LTS                       | bionic       | Debian
2  | Windows 10 Education (20191007) en-US    |              | Windows
3  | Windows 10 Education N (20191007) en-US  |              | Windows
4  | Windows 10 Enterprise (20191007) en-US   |              | Windows
5  | Windows 10 Enterprise N (20191007) en-US |              | Windows
6  | Windows 10 Pro (20191007) en-US          |              | Windows
7  | Windows 10 Pro N (20191007) en-US        |              | Windows
---|------------------------------------------|--------------|--------
hammer os set-default-template --id 2 --provisioning-template-id 122
Could not set the os default template:
  Template kind can't be blank
$ hammer template info --id 122
Id:                    122
Name:                  aaa_winpe_finish
Type:                  finish
Description:

Locked:                no
Operating systems:
    Windows 10 Education (20191007) en-US
    Windows 10 Education N (20191007) en-US
    Windows 10 Enterprise (20191007) en-US
    Windows 10 Enterprise N (20191007) en-US
    Windows 10 Pro (20191007) en-US
    Windows 10 Pro N (20191007) en-US
Locations:
    Default Location
Organizations:
    Default Organization
Template Combinations:

As stated before the templates are a export from the 1.23 install

Did some more testing. If the template is already selected a default the command works. If i deselect the template in the UI as default it also fails to run the command.

This sounds like a bug. Can you try doing the same via API to check if the issue is in hammer or foreman side?

https://theforeman.org/api/1.12/apidoc/v2/os_default_templates/update.html

It clearly states it needs it. But the UI does not.

This works:

API POST api/operatingsystems/2/os_default_templates
{
  "os_default_template": {
    "provisioning_template_id": "122",
    "template_kind_id": "6"
  }
}

If i leave it out i get Template kind can't be blank

Should i fill a issue for this one?

The link is for the 1.12 api doc, API documentation is the latest one on the site but since you are using 2.0-rc you can also see the updated api doc on your foreman server under https://your_foreman_server/apidoc/.

In any case, looks like this issue has been already reported and fixed a few days ago at: Bug #29274: hammer os set-default-template doesn't set default template - Hammer CLI - Foreman
I’ll make sure this gets into the 2.0 GA. Thanks for reporting it!

Thanks for your reply. I just patched the file on my machine and it seems to have fixed the issue.

1 Like