Unable to create new host using Foreman API – missing finishing template

foreman

I'm hoping this belongs on server fault…

I'm trying to create a host using the foreman API (using hammer, but POSTing the host payload gives me the same result). Each time, it complains that I'm lacking a finishing template.

The error message from the API is this: No finish templates were found for this host, make sure you define at least one in your CentOS 6.7 settings

How do I specify a finishing template when creating a host via Foreman API?

Nothing in the documentation tells me how to provide a finishing template selection when creating the host. Doing this in the Foreman UI with the same settings works just fine. When I click on "Resolve" in the provisioning templates section, I can see my finishing template as well.

Some details: this is Foreman 1.10.1 against a VMWare Cluster

Here's my host payload

  "host" => {
                          "name" => "ez-apitesthost",
                   "location_id" => 1,
               "organization_id" => 5,
                "environment_id" => 9,
               "architecture_id" => 1,
            "operatingsystem_id" => 2,
           "compute_resource_id" => 2,
                     "root_pass" => "password",
                  "hostgroup_id" => 73,
                      "image_id" => 19,
                         "build" => true,
                       "enabled" => true,
              "provision_method" => "image",
                       "managed" => true,
            "compute_profile_id" => 11,
            "compute_attributes" => {
                        "cpus" => "1",
              "corespersocket" => "2",
                   "memory_mb" => "4096",
                     "cluster" => "MYCLUSTER01",
                        "path" => "/Datacenters/MYDC/vm",
                    "guest_id" => "centos64Guest",
        "scsi_controller-type" => "ParaVirtualSCSIController"
          "volumes_attributes" => {
            "0" => {
                "datastore" => "dc_sata_01"
            }
        }
    },
                      "owner_id" => "75",
                     "overwrite" => true,
    "host_parameters_attributes" => {},
         "interfaces_attributes" => {
        "0" => {
                          "type" => "interface",
                          "name" => "ez-apitesthost",
                     "domain_id" => "1",
                     "subnet_id" => "2",
                       "managed" => "false",
                       "primary" => "true",
                     "provision" => "true",
            "compute_attributes" => {
                   "type" => "VirtualVmxnet3",
                "network" => "internal vlan"
            }
        }
    }
}

here's the response

{
"error" => {
               "id" => nil,
           "errors" => {
                       "base" => [
            [0] "No finish templates were found for this host, make sure you define at least one in your CentOS 6.7 settings"
        ],
                   "conflict" => [],
        "interfaces.conflict" => []
    },
    "full_messages" => [
        [0] "No finish templates were found for this host, make sure you define at least one in your CentOS 6.7 settings"
    ]
}

Best Answer

The problem here is that the OS you're using has no finish template associated to it. That's not something you have to do when creating a host, but when creating the OS.

Go to Hosts > Operating Systems > CentOS 6.7 and choose a finish template from the list in there. If you don't have any, I'd recommend choosing Kickstart finish. What it does is just installing Puppet and telling Foreman 'hey! I finished installing :)'

Here's what you're looking for:

OS finish template selection

If you don't see any finish templates, go to Host > Provisioning Templates, look for 'Kickstart default finish' and associate it with CentOS 6.7. After that you should be able to set it. This is what you should see:

provisioning templates associate with OS


Once your OS has a finish template associated with it, it should resolve just fine. If it cannot find a finish template even in this case, ensure you're providing the right OS options.

Related Topic