Foreman Provisioning host APIs

Hi Guys,
I have installed the centOS as baremetal server provisioning from the GUI.
but want to try provision the host using the foreman API so can someone please help me out with the APIs of the host provisioning with custom disk partition.

Thanks

How are you currently provisioning a server. Is it from a discovered host?

How do you wish to provision a server, through DHCP, or boot disk?

Hi Magarvo,
Yes your guess is right, I am using the auto discovery & provisioning from discovered host.
And server are booting from PXE to get the TCP address from the DHCP.

Thanks

You can use hammer -d tool to do what you want, the debug flag will show you requests and response JSON communication which you can use as an example.

Hi Izap,
Thanks for your reply–
as suggested by you even tried provisioning host from hammer command but after executing below the command
hammer -d discovery provision --id “25” --location “Default Location” --organization “Default Organization” --architecture “x86_64” --operatingsystem “CentOS 7.6.1810” --puppet-environment “production” --provision-method “build” --domain “examlab.com” --provision-method “build” --pxe-loader “PXELinux BIOS” --partition-table “Kickstart Default” --root-password “XXXX” --subnet “PXE-Boot” --medium “CentOS-arc” --interface “identifier=enp0s10f0, mac=00:15:5d:e0:02:56, managed=true, type=Nic::Managed”

getting error on the server-

but I am able to provision the discovered host from the Foreman GUI successfully.
so what is wrong here? can you please help me out here?

thanks

so after checking the pxelinux.cfg/01-00-15-5d-e0-02-56

DEFAULT menu
MENU TITLE Booting local disk (ESC to stop)
TIMEOUT 200
DEFAULT local_chain_hd0

LABEL local
MENU LABEL Default local boot
MENU DEFAULT
LOCALBOOT 0

LABEL local_primary
MENU LABEL Default local boot from primary hard drive
LOCALBOOT 0x80

LABEL local_skip
MENU LABEL Boot from the next BIOS device
LOCALBOOT -1

LABEL local_chain_hd0
MENU LABEL Chainload the first hard drive (hd0)
COM32 chain.c32
APPEND hd0

LABEL local_chain_hd1
MENU LABEL Chainload the second hard drive (hd1)
COM32 chain.c32
APPEND hd1

above file is getting created which doesnt have parameter which it should be…that is my guess .

You are missing “build” flag, when its set Foreman creates installation PXE configuration, when it’s not set the PXE is set to boot from local drive which fails because it’s apparently empty. Set it to “true” and you should be fine.

1 Like

Thanks IZap for your kind reply.

but after adding the --build “true” flag getting below error

DEBUG 2019-09-05T18:33:02 API] Using authenticator: HammerCLIForeman::Api::SessionAuthenticatorWrapper
[ERROR 2019-09-05T18:33:03 API] 500 Internal Server Error
[DEBUG 2019-09-05T18:33:03 API] {
    "error" => {
        "message" => "resource have no errors"
    }
}
[DEBUG 2019-09-05T18:33:03 Exception] Using exception handler HammerCLIForeman::ExceptionHandler#handle_internal_error
[ERROR 2019-09-05T18:33:03 Exception] resource have no errors
Could not create the host:
  resource have no errors
[ERROR 2019-09-05T18:33:03 Exception]

RestClient::InternalServerError (500 Internal Server Error):
    /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/abstract_response.rb:223:in `exception_with_response'
    /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/abstract_response.rb:103:in `return!'
    /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:353:in `block in rest_client_call_block'
    /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:807:in `process_result'
    /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:725:in `block in transmit'
    /opt/rh/rh-ruby25/root/usr/share/ruby/net/http.rb:910:in `start'
    /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:715:in `transmit'
    /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:145:in `execute'
    /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/request.rb:52:in `execute'
    /opt/theforeman/tfm/root/usr/share/gems/gems/rest-client-2.0.1/lib/restclient/resource.rb:76:in `put'
    /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:327:in `call_client'
    /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:240:in `http_call'
    /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:190:in `call_action'
    /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/api.rb:185:in `call'
    /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-bindings-0.2.2/lib/apipie_bindings/resource.rb:21:in `call'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.17.1/lib/hammer_cli/apipie/command.rb:53:in `send_request'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-0.17.2/lib/hammer_cli_foreman/commands.rb:188:in `send_request'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.17.1/lib/hammer_cli/apipie/command.rb:34:in `execute'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.17.1/lib/hammer_cli/abstract.rb:69:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/subcommand/execution.rb:11:in `execute'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.17.1/lib/hammer_cli/abstract.rb:69:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/subcommand/execution.rb:11:in `execute'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.17.1/lib/hammer_cli/abstract.rb:69:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:132:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.17.1/bin/hammer:147:in `<top (required)>'
    /usr/bin/hammer:23:in `load'
    /usr/bin/hammer:23:in `<main>'

You need to investigate why it failed, this is error from hammer CLI which is not very useful. Please make sure to output your reply correctly, I fixed it for you.

Ok thanks for your help. if Hammer is not working as expected then will foreman API will work
since I want to integrate foreman with my internal system to provision the discovered host.
so what best way to go about.

thanks

Hi Guys,

one think i have notice that when I am provisining discovered host from the GUI after the submission of the details it also generate the Token and then os installation get started.
but incase of discovered host provisioing it is not generating the token for provisioning and dont know why …

appriciate if any can help me here to get out of the issue…

thanks

Thanks Izap.

after adding the --build “true” flag and command was not working but when I created new host group and configure the required parameter such as Name
Environment
Puppet Master
Puppet CA
domain
ipv4 subnet
Architecture
Operating system
Media
Partition Table
Location
Organizations

after this run the command and host got created.

but without host group below error is occuring
Could not create the host:
resource have no errors

and now I dont know why it is not working in community if any one can help here to fix this hammer discovery provision command issue…

You need to dig in the logs on the Foreman server, what do you see in the production.log. Please only paste the relevant errors and format properly.

Hi lzap,

this is the error in log file--
2019-09-09T15:12:33 [I|app|d2ad31fe]   Parameters: {"location_id"=>2, "organization_id"=>1, "discovered_host"=>{"environment_id"=>1, "architecture_id"=>1, "domain_id"=>1, "operatingsystem_id"=>1, "medium_id"=>10, "subnet_id"=>1, "build"=>true, "provision_method"=>"build", "pxe_loader"=>"PXELinux BIOS", "root_pass"=>"[FILTERED]"}, "apiv"=>"v2", "id"=>"49"}
2019-09-09T15:12:33 [I|app|d2ad31fe] Current user set to admin (admin)
2019-09-09T15:12:34 [W|app|d2ad31fe] Not queueing Host::Managed: ["Ptable can't be blank unless a custom partition has been defined"]
2019-09-09T15:12:34 [W|app|d2ad31fe] Not queueing Host::Managed: ["Ptable can't be blank unless a custom partition has been defined"]
2019-09-09T15:12:34 [W|app|d2ad31fe] Not queueing Host::Managed: ["Ptable can't be blank unless a custom partition has been defined"]
2019-09-09T15:12:34 [W|app|d2ad31fe] Not queueing Discovery reboot: Ptable can't be blank unless a custom partition has been defined
2019-09-09T15:12:34 [W|app|d2ad31fe] Action failed
RuntimeError: resource have no errors

Hey,

I am lzap just for the record :slight_smile: I have reformatted the paste for you, please be careful when pasting text and format it properly.

The error says it all - you don’t have partition table set, so it cannot proceed with provisioning. Provide that and it will work.

Ohh >>

But if you see my command i have added the ptable flag
ammer discovery provision --id “49” --location “Default Location” --organization “Default Organization” --architecture “x86_64” --operatingsystem “CentOS 7.6.1810” --puppet-environment “production” --domain “examlab.com” --provision-method “build” --pxe-loader “PXELinux BIOS” --partition-table “nm-centos” --medium “CentOS-NM” --root-password “qwe@123#” --subnet “PXE-Boot” --interface “identifier=enp0s10f0, mac=00:15:5d:e0:02:5e, managed=true, type=Nic::Managed” --build “true”

thanks

Hi Izap,

Instead of --partition-table i used --partition-table-id and then it works.

[root@foremansrv /]# hammer discovery provision --id “52” --location “Default Location” --organization “Default Organization” --architecture “x86_64” --operatingsystem “CentOS 7.6.1810” --puppet-environment “production” --provision-method “build” --domain “examlab.com” --pxe-loader “PXELinux BIOS” --partition-table-id “104” --root-password “qwe@123#” --subnet “PXE-Boot” --medium “CentOS-NM” --interface “identifier=enp0s10f0, mac=00:15:5d:e0:02:56, managed=true, type=Nic::Managed” --build “true”
Host created

Thanks for your help–

Thanks

Probably a bug in “host edit” hammer command or hammer discovery itself. Bug #27827: Hammer discovery provision option --partition-table does not work - Discovery - Foreman

Anyone is welcome to work on this bug.