Create a label via the API

I use the API to auto-register docker hosts to a Rancher environment and it works well. Hosts in our case are maintained in AWS via an auto-scaling group which runs a user-data script to do the work. We have a number of these for different types of hosts (see below).

However, I also create a number of differently categorised hosts which are differentiated by a label. Those labels are used by scheduling rules. Problem is I have been unable to find a way of creating the label at the time I auto-register the host.

Taking an example, let’s say I want to create a label called HOST_TYPE with a value of LB. How can I do that at the same time as registering the host, fully automated ?

Regards

Fraser.

You can set host labels by setting an environment variable in the docker run command for the agent with url-encoded pairs, e.g., -e CATTLE_HOST_LABELS='foo=bar&baz=qwer'. The custom Add Host UI also has an option for it and shows you the command.

Ah yes, I had forgotten about that, perfect, thx Vincent.

For the benefit of others it’s also documented here (RTFM) : http://docs.rancher.com/rancher/v1.2/en/hosts/custom/