[os-vagrant] Register a Custom Node to Server w/out using the UI

To register a Custom Node through the UI; I set the Host Registration URL. Then I provide the Custom Host IP to get a copy-paste docker command. Finally, I paste that command on that host to get it registered with the server. Got it.

Since I am using Vagrant, I suspect I can accomplish all of this from the Vagrantfile, using the RESTful API of the server. I’ve looked through the API, and it’s huge.

What is the RESTful endpoint for setting the Host Registration URL?

I stumbled across the answer when I noticed I could reverse engineer the curl calls from the Rancher Admin->Audit tab. The sequence I ended up using;

  • For the Rancher VM
    curl -X PUT -d {"activeValue":"http://#{rancher_ip}:#{rancher_port}", "id":"1as2", "name":"api.host", "source":"Database", "value":"http://#{rancher_ip}:#{rancher_port}"} http://#{rancher_ip}:#{rancher_port}/v1/activesettings/1as2
    curl -X POST -d {} http://#{rancher_ip}:#{rancher_port}/v1/projects/1a5/registrationtokens

  • For each Cattle Agent VM
    curl -X GET http://#{rancher_ip}:#{rancher_port}/v1/registrationTokens | grep -o 'sudo[^"]*' | bash