Provisioning discovered host via API not working for me

Problem:
When I try to provision from API with:

curl -kSs -H "Content-Type:application/json" -H "Accept:application/json" -u admin:$PASSWORD -X PUT -d '{"id":"47","discovered_host":{"host
    group_id":"2"}}' https://10.137.100.20/api/v2/discovered_hosts/47/

Host just reboots and try to boot from disk (but booting fails, no installation is performed).

Expected outcome:
Host should be provisioned and installed with all parameters defined in host group. When i try to provision same host via web gui (i just select host group), everything works OK.

Foreman and Proxy versions:
version 1.21.3

Foreman and Proxy plugin versions:
Discovery plugin version 14.0.1

Other relevant data:
production log:

2019-06-27T18:35:06 [I|app|fbedd53c] Started PUT "/api/v2/discovered_hosts/47/" for 10.93.0.1 at 2019-06-27 18:35:06 +0200
2019-06-27T18:35:06 [I|app|fbedd53c] Processing by Api::V2::DiscoveredHostsController#update as JSON
2019-06-27T18:35:06 [I|app|fbedd53c]   Parameters: {"id"=>"47", "discovered_host"=>{"hostgroup_id"=>"2"}, "apiv"=>"v2"}
2019-06-27T18:35:06 [I|app|fbedd53c] Authorized user admin(Admin User)
2019-06-27T18:35:06 [I|app|fbedd53c] Current user set to admin (admin)
2019-06-27T18:35:07 [I|app|fbedd53c] Create DHCP reservation mac56a85f3e43b6.serverbar2.local for mac56a85f3e43b6.serverbar2.local-56:a8:5f:3e:43:b6/10.137.111.167
2019-06-27T18:35:07 [I|app|fbedd53c] Add DNS A record for mac56a85f3e43b6.serverbar2.local/10.137.111.167
2019-06-27T18:35:07 [I|app|fbedd53c] Add DNS PTR record for 10.137.111.167/mac56a85f3e43b6.serverbar2.local
2019-06-27T18:35:07 [I|blo|fbedd53c] Unattended render of 'pxelinux_chainload' = 'adb6880ad1c5c8384a570953f57b4d58d6184c509ae7d283d469bd36fe732550'

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

2019-06-27T18:35:07 [I|blo|fbedd53c] Unattended render of 'PXELinux default local boot' = '5eb0185e676a01ed8e54fbaad26ff72dc6b23ea2513ab77f04176037659e3321'



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


2019-06-27T18:35:07 [I|app|fbedd53c] Deploying TFTP PXELinux configuration for mac56a85f3e43b6.serverbar2.local
2019-06-27T18:35:07 [I|blo|fbedd53c] Unattended render of 'pxegrub2_chainload' = 'b2ca987ed433a57cbb4bf7184edbeeeaf114f658fbe2411aeaea6995e71e0bd4'

insmod part_gpt
insmod fat
insmod chain

menuentry 'Chainload Grub2 EFI from ESP' --id local_chain_hd0 {
  echo Chainloading Grub2 EFI from ESP, enabled devices for booting:
  ls
  echo "Trying /EFI/fedora/shim.efi "
  unset root
  search --file --no-floppy --set=root /EFI/fedora/shim.efi
  if [ -f ($root)/EFI/fedora/shim.efi ]; then
    chainloader ($root)/EFI/fedora/shim.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/fedora/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/fedora/grubx64.efi
  if [ -f ($root)/EFI/fedora/grubx64.efi ]; then
    chainloader ($root)/EFI/fedora/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/redhat/shim.efi "
  unset root
  search --file --no-floppy --set=root /EFI/redhat/shim.efi
  if [ -f ($root)/EFI/redhat/shim.efi ]; then
    chainloader ($root)/EFI/redhat/shim.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/redhat/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/redhat/grubx64.efi
  if [ -f ($root)/EFI/redhat/grubx64.efi ]; then
    chainloader ($root)/EFI/redhat/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/centos/shim.efi "
  unset root
  search --file --no-floppy --set=root /EFI/centos/shim.efi
  if [ -f ($root)/EFI/centos/shim.efi ]; then
    chainloader ($root)/EFI/centos/shim.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/centos/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/centos/grubx64.efi
  if [ -f ($root)/EFI/centos/grubx64.efi ]; then
    chainloader ($root)/EFI/centos/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/debian/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/debian/grubx64.efi
  if [ -f ($root)/EFI/debian/grubx64.efi ]; then
    chainloader ($root)/EFI/debian/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/ubuntu/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/ubuntu/grubx64.efi
  if [ -f ($root)/EFI/ubuntu/grubx64.efi ]; then
    chainloader ($root)/EFI/ubuntu/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/sles/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/sles/grubx64.efi
  if [ -f ($root)/EFI/sles/grubx64.efi ]; then
    chainloader ($root)/EFI/sles/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/opensuse/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/opensuse/grubx64.efi
  if [ -f ($root)/EFI/opensuse/grubx64.efi ]; then
    chainloader ($root)/EFI/opensuse/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/Microsoft/boot/bootmgfw.efi "
  unset root
  search --file --no-floppy --set=root /EFI/Microsoft/boot/bootmgfw.efi
  if [ -f ($root)/EFI/Microsoft/boot/bootmgfw.efi ]; then
    chainloader ($root)/EFI/Microsoft/boot/bootmgfw.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo Partition with known EFI file not found, update 'pxegrub2_chainload' template.
  echo The system will halt in 2 minutes or press ESC to halt immediately.
  sleep -i 120
  halt --no-apm
}

menuentry 'Chainload into BIOS bootloader on first disk' --id local_chain_legacy_hd0 {
  set root=(hd0,0)
  chainloader +1
  boot
}

menuentry 'Chainload into BIOS bootloader on second disk' --id local_chain_legacy_hd1 {
  set root=(hd1,0)
  chainloader +1
  boot
}

2019-06-27T18:35:07 [I|blo|fbedd53c] Unattended render of 'PXEGrub2 default local boot' = '16ed7c277a69f8cfee02178e21368d31d7e8c944ed8aac3dae49aab0a2845951'



set default=local
set timeout=20


insmod part_gpt
insmod fat
insmod chain

menuentry 'Chainload Grub2 EFI from ESP' --id local_chain_hd0 {
  echo Chainloading Grub2 EFI from ESP, enabled devices for booting:
  ls
  echo "Trying /EFI/fedora/shim.efi "
  unset root
  search --file --no-floppy --set=root /EFI/fedora/shim.efi
  if [ -f ($root)/EFI/fedora/shim.efi ]; then
    chainloader ($root)/EFI/fedora/shim.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/fedora/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/fedora/grubx64.efi
  if [ -f ($root)/EFI/fedora/grubx64.efi ]; then
    chainloader ($root)/EFI/fedora/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/redhat/shim.efi "
  unset root
  search --file --no-floppy --set=root /EFI/redhat/shim.efi
  if [ -f ($root)/EFI/redhat/shim.efi ]; then
    chainloader ($root)/EFI/redhat/shim.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/redhat/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/redhat/grubx64.efi
  if [ -f ($root)/EFI/redhat/grubx64.efi ]; then
    chainloader ($root)/EFI/redhat/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/centos/shim.efi "
  unset root
  search --file --no-floppy --set=root /EFI/centos/shim.efi
  if [ -f ($root)/EFI/centos/shim.efi ]; then
    chainloader ($root)/EFI/centos/shim.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/centos/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/centos/grubx64.efi
  if [ -f ($root)/EFI/centos/grubx64.efi ]; then
    chainloader ($root)/EFI/centos/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/debian/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/debian/grubx64.efi
  if [ -f ($root)/EFI/debian/grubx64.efi ]; then
    chainloader ($root)/EFI/debian/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/ubuntu/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/ubuntu/grubx64.efi
  if [ -f ($root)/EFI/ubuntu/grubx64.efi ]; then
    chainloader ($root)/EFI/ubuntu/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/sles/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/sles/grubx64.efi
  if [ -f ($root)/EFI/sles/grubx64.efi ]; then
    chainloader ($root)/EFI/sles/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/opensuse/grubx64.efi "
  unset root
  search --file --no-floppy --set=root /EFI/opensuse/grubx64.efi
  if [ -f ($root)/EFI/opensuse/grubx64.efi ]; then
    chainloader ($root)/EFI/opensuse/grubx64.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo "Trying /EFI/Microsoft/boot/bootmgfw.efi "
  unset root
  search --file --no-floppy --set=root /EFI/Microsoft/boot/bootmgfw.efi
  if [ -f ($root)/EFI/Microsoft/boot/bootmgfw.efi ]; then
    chainloader ($root)/EFI/Microsoft/boot/bootmgfw.efi
    echo "Found Grub2 at $root"
    sleep 2
    boot
  fi
  echo Partition with known EFI file not found, update 'pxegrub2_chainload' template.
  echo The system will halt in 2 minutes or press ESC to halt immediately.
  sleep -i 120
  halt --no-apm
}

menuentry 'Chainload into BIOS bootloader on first disk' --id local_chain_legacy_hd0 {
  set root=(hd0,0)
  chainloader +1
  boot
}

menuentry 'Chainload into BIOS bootloader on second disk' --id local_chain_legacy_hd1 {
  set root=(hd1,0)
  chainloader +1
  boot
}


2019-06-27T18:35:07 [I|app|fbedd53c] Deploying TFTP PXEGrub2 configuration for mac56a85f3e43b6.serverbar2.local
2019-06-27T18:35:07 [I|blo|fbedd53c] Unattended render of 'pxegrub_chainload' = '3cba491d75f2760a5b570d2978dc2ea7ec2cf42a1743a7d4d7bbbd5470d567eb'

fallback=1 2 3 4 5 6 7 8 9 10
  
title Chainload Grub from /EFI/fedora or try next
  rootnoverify (hd0,0)
  chainloader /EFI/fedora/grubx64.efi
  
title Chainload Grub from /EFI/redhat or try next
  rootnoverify (hd0,0)
  chainloader /EFI/redhat/grubx64.efi
  
title Chainload Grub from /EFI/centos or try next
  rootnoverify (hd0,0)
  chainloader /EFI/centos/grubx64.efi
  
title Chainload Grub from /EFI/debian or try next
  rootnoverify (hd0,0)
  chainloader /EFI/debian/grubx64.efi
  
title Chainload Grub from /EFI/ubuntu or try next
  rootnoverify (hd0,0)
  chainloader /EFI/ubuntu/grubx64.efi
  
title Chainload Grub from /EFI/sles or try next
  rootnoverify (hd0,0)
  chainloader /EFI/sles/grubx64.efi
  
title Chainload Grub from /EFI/opensuse or try next
  rootnoverify (hd0,0)
  chainloader /EFI/opensuse/grubx64.efi
  
title Chainload Grub from /EFI/Microsoft or try next
  rootnoverify (hd0,0)
  chainloader /EFI/Microsoft/grubx64.efi
  
title Chainload Grub from /EFI/EFI or try next
  rootnoverify (hd0,0)
  chainloader /EFI/EFI/grubx64.efi
  
title Chainload Grub from /EFI/local_chain_hd0 or try next
  rootnoverify (hd0,0)
  chainloader /EFI/local_chain_hd0/grubx64.efi
  
title Chainload into bootloader on first disk
  root (hd0,0)
  chainloader +1

2019-06-27T18:35:07 [I|blo|fbedd53c] Unattended render of 'PXEGrub default local boot' = '6a8c8813a70530615c0391fc14eda10330654c67f4258fc7bff68dd7d5e5e0c1'



default=0
timeout=20


fallback=1 2 3 4 5 6 7 8 9 10
  
title Chainload Grub from /EFI/fedora or try next
  rootnoverify (hd0,0)
  chainloader /EFI/fedora/grubx64.efi
  
title Chainload Grub from /EFI/redhat or try next
  rootnoverify (hd0,0)
  chainloader /EFI/redhat/grubx64.efi
  
title Chainload Grub from /EFI/centos or try next
  rootnoverify (hd0,0)
  chainloader /EFI/centos/grubx64.efi
  
title Chainload Grub from /EFI/debian or try next
  rootnoverify (hd0,0)
  chainloader /EFI/debian/grubx64.efi
  
title Chainload Grub from /EFI/ubuntu or try next
  rootnoverify (hd0,0)
  chainloader /EFI/ubuntu/grubx64.efi
  
title Chainload Grub from /EFI/sles or try next
  rootnoverify (hd0,0)
  chainloader /EFI/sles/grubx64.efi
  
title Chainload Grub from /EFI/opensuse or try next
  rootnoverify (hd0,0)
  chainloader /EFI/opensuse/grubx64.efi
  
title Chainload Grub from /EFI/Microsoft or try next
  rootnoverify (hd0,0)
  chainloader /EFI/Microsoft/grubx64.efi
  
title Chainload Grub from /EFI/EFI or try next
  rootnoverify (hd0,0)
  chainloader /EFI/EFI/grubx64.efi
  
title Chainload Grub from /EFI/local_chain_hd0 or try next
  rootnoverify (hd0,0)
  chainloader /EFI/local_chain_hd0/grubx64.efi
  
title Chainload into bootloader on first disk
  root (hd0,0)
  chainloader +1


2019-06-27T18:35:07 [I|app|fbedd53c] Deploying TFTP PXEGrub configuration for mac56a85f3e43b6.serverbar2.local
2019-06-27T18:35:07 [I|blo|fbedd53c] Unattended render of 'iPXE default local boot' = '48af61df6a747c8546d165712d2d273a4d05021ee761f17b989493ca75a0efe2'
#!ipxe

# Skips booting from network and continues booting from next device
exit

2019-06-27T18:35:07 [I|app|fbedd53c] Deploying TFTP iPXE configuration for mac56a85f3e43b6.serverbar2.local
2019-06-27T18:35:07 [I|app|fbedd53c] Processed 7 tasks from queue 'Host::Managed Main', completed 7/7
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on name mac56a85f3e43b6, mac56a85f3e43b6.serverbar2.local
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on root_pass , $5$YArpOWgmRPs7zR5M$4Fc4NcltHXFFKLon8iGxVj33KUuyIl6BAGO7Ub2mm32
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on architecture_id , 1
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on operatingsystem_id , 1
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on environment_id , 1
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on ptable_id , 106
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on medium_id , 2
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on hostgroup_id , 2
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on managed false, true
2019-06-27T18:35:07 [I|aud|fbedd53c] Host::Base (47) update event on grub_pass , $5$YArpOWgmRPs7zR5M$4Fc4NcltHXFFKLon8iGxVj33KUuyIl6BAGO7Ub2mm32
2019-06-27T18:35:07 [I|aud|fbedd53c] Nic::Managed (85) update event on name mac56a85f3e43b6, mac56a85f3e43b6.serverbar2.local
2019-06-27T18:35:07 [I|aud|fbedd53c] Nic::Managed (85) update event on domain_id , 1
2019-06-27T18:35:08 [I|app|fbedd53c] Processed 1 tasks from queue 'Host::Managed Post', completed 1/1
2019-06-27T18:35:08 [I|app|fbedd53c]   Rendering vendor/ruby/2.3.0/gems/foreman_discovery-14.0.1/app/views/api/v2/discovered_hosts/update.json.rabl
2019-06-27T18:35:08 [I|app|fbedd53c]   Rendered vendor/ruby/2.3.0/gems/foreman_discovery-14.0.1/app/views/api/v2/discovered_hosts/update.json.rabl (1.0ms)
2019-06-27T18:35:08 [I|app|fbedd53c] Completed 200 OK in 1447ms (Views: 2.3ms | ActiveRecord: 84.7ms)

Hey, this API endpoint behavior is the same as “Edit Host”, you need to set all flags, or at least a hostgroup that has all required flags to initiate provisioning.

1 Like

Thank you for your reply.
But i did this: i added hostgroup that has all required settings:

-d '{"id":"47","discovered_host":{"hostgroup_id":"2"}}'

When i click on the host in “discovered hosts” in web gui, all i do is select proper hostgroup and host is provisioned and installed without any problems. Maybe I am doing somethinmg wrong in my json added via PUT?

Here is output of my /api/hostgroups/2:

{
"subnet_id": null,
"subnet_name": "bla2",
"operatingsystem_id": 1,
"operatingsystem_name": "Debian 9.9",
"domain_id": null,
"domain_name": "bla2.local",
"environment_id": null,
"environment_name": "production",
"compute_profile_id": null,
"compute_profile_name": null,
"ancestry": "1",
"parent_id": 1,
"parent_name": "bla2-test1",
"ptable_id": 106,
"ptable_name": "Preseed default",
"medium_id": 2,
"medium_name": "Debian mirror",
"pxe_loader": "PXELinux BIOS",
"subnet6_id": null,
"subnet6_name": null,
"architecture_id": null,
"architecture_name": "x86_64",
"realm_id": null,
"realm_name": null,
"created_at": "2019-05-31T14:08:46.790+02:00",
"updated_at": "2019-05-31T14:08:46.932+02:00",
"id": 2,
"name": "bla2-test1-debian",
"title": "bla2-test1/bla2-test1-debian",
"description": "",
"puppet_proxy_id": null,
"puppet_proxy_name": null,
"puppet_ca_proxy_id": null,
"puppet_ca_proxy_name": null,
"puppet_proxy": null,
"puppet_ca_proxy": null,
"parameters": [],
"template_combinations": [],
"puppetclasses": [],
"config_groups": [],
"all_puppetclasses": [],
"locations": [
{
"id": 1,
"name": "Default Location",
"title": "Default Location",
"description": ""
}
],
"organizations": [
{
"id": 2,
"name": "Default Organization",
"title": "Default Organization",
"description": ""
}
]
}
1 Like

OK, i found out what was missing:

-d '{"id":"47","discovered_host":{"hostgroup_id":"2"}}'

is not enough!!!

But, if i put it like this:

-d '{"id":47,"discovered_host":{"hostgroup_id":2,"build":"true"}}'

Everything works!

Foreman is a great project, with not-so-great documentation :slight_smile: i had to look in source to figure it out :smiley:

Oh right, build flag is not part of a hostgroup makes sense.

1 Like

We know, we are trying to improve: https://github.com/theforeman/foreman-documentation/tree/master/guides

1 Like