Mapping salt ids to a name-label
From past experience with Chef for configuration management, we realized that using hostname as a minion id is problematic for a few reasons, such as:
- a hostname is not guaranteed to be unique at all time (e.g. especially ugly example: VM cloning)
- Hostname could be changed without updating minion config, causing Salt id names to drift out of sync.
Although it could be possible to work around by requiring hostnames to be set via Salt, I decided to tackle it by using UUIDs for minion ids. However, UUIDs are very ugly to deal with in both the top file and the CLI. However, Salt was relatively easy to extend using a custom runner and the top file needed to be auto-generated for tracking and ACL purposes anyways. So, I wrote a custom runner that handled both user ACLs (similar to the request in https://github.com/saltstack/salt/issues/2008) and maps pretty names to uuids (pulled from our internal inventory tool). The custom runner maps passed in name-labels to uuids before passing to Salt internals and also maps uuids to name-labels when the minion output returns.
However, I'm wondering if the the ability to match uuids to name-labels is a common case (and a potential new feature) or if there are other recommendations on how to accomplish this.
Using a different attribute (such as a custom grain) is not as good for targeting since:
- Salt seems to know about the uniqueness of minion ids and returns immediately if a minion is targeting by id. It's annoying to have to wait or ctrl+c after the single minion returned. Also, if the minion is down, Salt knows about it and reports 'Minion did not return' for the given minion.
- The default Salt output prints the minion id. So, if a uuid is used for the minion id, targetting by a custom grain would give output such as:
$ salt -G 'custom-grain:name-label' test.ping
uuid-9a0d58fb43c64cf0842c1d3db24e6964:
True
Is minion id re-mapping a potential future feature, or are there better ways of accomplishing my use case without using a custom runner?
http://docs.saltstack.com/ref/configuration/minion.html#std:conf_minion-id
Is this what you're after?
Thanks for the recommendations and use cases!
I did want to comment on your (1) above -- we have an open issue to extend master-side minion matching to grains and other targeting forms to make them as responsive as glob matching. That will definitely be nice for use cases where minion IDs are less than useful. =) But you're right, the output it still sorted by ID.
All in all, this is a great idea, and I'm going to put it in Approved for Future.
@kaithar I don't think that's what he's looking for -- I can only assume he's already using that to configure the ID to be the UUID. shrugs
@basepi could be, but the way I read it is that he's rewriting on the master side
@kaithar Yup, as @basepi assumed, I'm pre-allocating minion keys and auto-setting http://docs.saltstack.com/ref/configuration/minion.html#std:conf_minion-id to a UUID in each minion config and recording the UUID used in an inventory tool for later use by the custom runner.
We propose adding an optional uuid to name-label mapping to the CkMinions class in salt.utils.minions, that is applied before matching globs/regexes. We would translate the uuids to name-labels before responding to clients, in _handle_payload (salt.master:571) The name-label mapping would be supplied by a pillar. Does this sound like a good solution?
Sorry, I haven't looked at this in a couple of weeks, but if you're manually (or automatically) assigning minion IDs in the conf, then why don't you just assign those sane names instead of the UUIDs at that step?
Maybe I'm missing the point, but I was confused as I was re-reading through this thread.
The main reason is that it allows changing a name-label of the minion without requiring an update of the minion config and the a restart of the remote daemon. Using a UUID to name-label mappings way provides a much better guarantee of the names used on the cli being in sync with our inventory system.
Secondarily, our inventory system does not enforce uniqueness of machine names. If a machine is started for the first time when another machine with the same name exists, they'd have identical minion ids. However, we could adjust the inventory system to enforce uniqueness so this is a more minor concern.
We're interested in submitting a pull request for this change as doing the mapping lower in Salt would be useful to us and we thought others might benefit from this as well.
Ah, that makes sense. When Tom is back in town I'll ask him to look at this, assess its feasibility.
Here is a rough proposal of what it might look like in the code (the mapping is hardcoded for now)
https://github.com/hulu/salt/tree/pretty-name-mapping
@thatch45 Andrew has a rough proposal in the branch above. As far as defining the mapping, there are a few option that I can think of:
- Dictionary built from a yaml file somewhere in the master config directory.
- Run a pillar file on the master, passing in the minion's grains or just just the minion's id.
I'm not too sure about the second approach, faking the environment of the minion is a bit hacky. But, if you can let us know how you'd prefer us to proceed, we can give you a complete pull request!
I manage openstack infrastructure and this feature would be quite helpful in the long run. My issue is that the default, simplest mode for Openstack is to set the display name of the openstack vm as the vm's hostname. This means two things in practice:
- hostnames are completely unpredictable
- hostnames will frequently float from one VM to another because the tenant usually lands on a naming convention that suits them and thus uses the same names over and over again when launching a new VM.
Basically, I'd love to know when this would be pulled into the salt main branch. :)
I personally decided not to continue work on the feature. The pretty-naming-branch is pretty far out of date now, but if you were interested - it could have a place to start.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.