Thoughts on moving hosts between environments (repurpose host)

I decided to keep simple inventory of servers in Ansible.
Setting hosts and adding them to environment is quite easy and there are few scripts that do that well enough.
But I have not seen script that check if host is in correct environment. It is possible “achieve” that by checking rancher agent container for registration token but token changes so it is not very robust or safe.

Is there a way to check from host in which environment host is? I have skimmed metadata docs and tried some stuff myself. AFAIK manually launched container has no way of detecting environment host is assigned to. Only environment_name is exposed in stack of a service.

It could be done by asking for host id in launched container with networking enabled on that host and then comparing it against environments list of hosts provided by Rancher. (that is just too hassle without much hoff)

It would be nice to have environment_id and environment_name also in host metadata. Stacks can’t have different environments and be on same host anyway so I don’t see the point of providing that information in stack object.