-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function to generate MAC addresses #1699
Comments
This seems like a reasonably decent idea. Until I (or someone else!) can implement this, one option is to define a template that calls mac.t: {{ define "hex" -}}
{{ random.Number 0 255 | printf "%02x" -}}
{{ end -}}
{{ define "mac" -}}
{{ template "hex" -}}
{{ range (seq 5) }}:{{ template "hex" }}{{ end -}}
{{end -}} then you can include that as a nested template: $ gomplate -t mac=mac.t -i 'mac is {{ template "mac" }}{{"\n"}}'
mac is 3b:c2:aa:86:b2:b9 |
Random MACs are good but IMHO the killer feature of ansible's This allows writing things like: mac: "{{ 'AA:BB' | community.general.random_mac( seed= hostname + '/' + nic ) }}") to get a (consistently reproducible) MAC based on hostname and nic (or on whatever else you please). The above is ansible's syntax; personally I think that it would be better to have two separate functions, one (say |
Ah, thanks for the followup - this makes sense. BTW, two functions aren't necessary - a single function can behave differently given different inputs. For example:
The concept of allowing a user-provided seed is interesting - this may be useful to add into the I can't promise that I'll be able to write this function any time soon - I have limited time to work on gomplate, and most of my gomplate-time is currently being used to get the v4.0 release ready... But if you're interested in contributing I would accept a PR for a function like this! |
TIA about the U/L bit in MAC addresses, which I think might be relevant for implementing this feature: https://en.wikipedia.org/wiki/MAC_address#Universal_vs._local_(U/L_bit) I doubt this would matter much in any practical scenario, but I think the new |
huh, good callout, TIL 😂 |
This issue is stale because it has been open for 60 days with no activity. Remove |
This issue is stale because it has been open for 60 days with no If it's still relevant, one of the following will remove the stale
|
Reopening as I still think this is useful, but can't commit to this for v4 |
Please add a function that allows generating MAC addresses based on some value (similar to ansible's community.general.random_mac when used with a seed)
The text was updated successfully, but these errors were encountered: