Foreman API - Enable rebuild on next boot

Hi,

We have a Foreman, Puppet, oVirt/RHV Setup. We have automated most tasks in
foreman with Ansible.

I know want to trigger a rebuild of a bunch of VMs via Ansible, but I can’t
find any documentation on how to do that. The only thing I see ist “Update
a host” via “PUT /api/hosts/:id” and pass a body like this:

---
host:
  build: 1

But this returns the following error:

  error:
    errors:
      base:
      - 'Failed to update a compute RHEV-XXX (oVirt) instance 
node1.example.com:
        Cannot add Virtual Disk. Disk node1.example.com_Disk1 in VM 
node1.example.com
        is already marked as boot.'
    full_messages:
    - 'Failed to update a compute RHEV-XXX (oVirt) instance 
node1.example.com:
      Cannot add Virtual Disk. Disk node1.example.com_Disk1 in VM 
node1.example.com
      is already marked as boot.'

How can I trigger the rebuild via the API?

Thank you
Marc

Hi,

Did you manage to work this out? We have a similar issue with foreman 1.16 + libvirt guests - once the build status is ‘Installed’ the build button in the UI is ‘greyed out’ and hovering over it reveals the message: enable rebuild on next host boot

It would be interesting to know how that can actually be triggered… it doesn’t seem to matter if the host is powered on or off…

Hi,

sadly there was no rebuild option in the rest API and we refused to script the GUI with things like selenium. We choose the brutal method: delete + create. Meaning we are removing the hosts from foreman and creating them again. Both via the API. Since we have the oVirt/RHV Plugin we need to trigger the delete and the create multiple times per host, to be able to build the host.

It’s not beautiful, but it works 99% of the time.

Cheers
Marc

I was going to say have you filled a issues for this in our issue tracker but I think it is possible today, just with 2 or 3 API calls:

  1. optionally use PUT, “/hosts/:id/rebuild_config”
  2. use PUT, "/hosts/:id/ to put it build mode
  3. use PUT, “/hosts/:id/power” to reboot

@sean797 Thank you. Which bodies do I have to send in the PUT requests. That was my initial question. I could neither find a documentation of this nor could I successfully guess a body.

With libvirt when I submit a PUT against api/hosts/:id the payload needs to have {“host”:{“build”: “true”}} - this will then trigger a build as expected - so this works for me, not sure about your original use case @Marc_Popp1 ?

The formatting on your original post was bad, so I missed the fact that you are already setting build true, presumably in your ansible yaml.

I did also notice there was an issue that I’d previously changed the underlying image that libvirt was using to install the host - even though I had updated the image path in the foreman UI - this had not updated the database so foreman was still trying to use the old image path. I’m not saying you are running into this issue as the error was different to yours, but I tracked that down by setting debug mode logging and enabling both app and sql logs to catch that issue.