saltstack-formulas / hostsfile-formula

Use minion IDs to keep /etc/hosts and hostnames consistent for clusters without DNS
http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
33 stars 89 forks source link

[FEATURE] Add ability to force overwrite entries if old names are already present #42

Open mdschmitt opened 2 years ago

mdschmitt commented 2 years ago

Is your feature request related to a problem?

If there's an existing minion that's replaced with another minion of the same name but different IP (and the original minion is renamed) the hostsfile formula will simply add an entry for the new node, and add the new name for the old node to the old node's entry. This means that the original name gets two entries in /etc/hosts. Visual example: Original node (the "before" state):

10.0.0.2  prometheus.my.domain.com

< Rename prometheus.my.domain.com minion_id to "prometheus-old.my.domain.com" > < Spin up new node and call it "prometheus.my.domain.com" >

Now when running hostsfile on any minions that already had the old entry, they grab both new and old node entries from the Mine, and their /etc/hosts looks like:

10.0.0.2  prometheus.my.domain.com prometheus-old.my.domain.com
10.0.0.3  prometheus.my.domain.com

Describe the solution you'd like

Add a "purge existing entries" behavior to the formula. Probably an if condition to add the clean flag to host.present in init.sls?

The intent would be to update minions' /etc/hosts to point prometheus.my.domain.com to the new minion and set the old entry to "prometheus-old.my.domain.com" only. Like so:

10.0.0.2  prometheus-old.my.domain.com
10.0.0.3  prometheus.my.domain.com

Describe alternatives you've considered

n/a

Additional context

n/a