So here’s my scenario. I’d like to set some host labels on my rancher agent that is running on rancheros. These labels should be based off information from the ec2 metadata service as I’m running on AWS. I am very stuck as to how to make this happen in RancherOS. Here’s what I’ve tried:
Use write_files to create a start.sh script that uses ros config to set rancher.environment.CATTLE_HOST_LABELS to what I need, then referencing said variable in my cloud-config like this:
services:
register:
environment:
CATTLE_HOST_LABELS
…other docker stuff…
This doesn’t seem to work. I was assuming the ros env command was applied to services that you use cloud-config to run, but maybe not?
Instead of using cloud-config, just set my user data to a simple bash script that runs the rancher agent container directly. In this scenario the container never launched.
Anyone got any better ideas on how I might achieve this?
I was able to follow the docs to get an agent running into Rancher and using the environment, but am still looking into doing it with the cloud-config.
The main hurdle that I’m not sure about is how to use the sudo ros env command while booting.
Here’s what I have tried:
After RancherOS is launched:
sudo ros set rancher.environment.CATTLE_HOST_LABELS 'foo=bar'
sudo ros env docker run -e CATTLE_HOST_LABELS --d --privileged -v /var/run/docker.sock:/var/run/docker.sock rancher/agent:v0.8.2 http://<rancher-server-ip>:8080/v1/projects/1a5/scripts/<registrationToken>
I believe having the equivalent in your cloud-config would set the environment.
#cloud-config
rancher:
environment:
CATTLE_HOST_LABELS: foo=bar #this is where you'd need to figure out how to set your metadata items
The part I’m still looking into is how to call the sudo ros env command to start your service that would use the environment variable that you just set.