Skip to content

Instantly share code, notes, and snippets.

@lavoiesl
Last active December 4, 2022 10:27
Show Gist options
  • Save lavoiesl/4539865 to your computer and use it in GitHub Desktop.
Save lavoiesl/4539865 to your computer and use it in GitHub Desktop.
Puppet: Generate a unique integer id base on the hostname
#
# Generate a unique integer id base on the hostname
# It works by stripping $domain from the $::fqdn,
# removing all characters except alphanumeric and converting to base 10
# $domain is provided if you have complex domains like *.hosting.example.com
#
class uniqueid (
$domain = $::domain,
) {
$node_id = inline_template("<%= '$::fqdn'.gsub('$domain','').gsub(/[^a-z0-9]/i,'').to_i(36) %>")
}
@CoolCold
Copy link

CoolCold commented Dec 4, 2022

for server_id in MySQL, used extra modulo % operator on top, giving range from 0 to 255

    $_server_id = Integer(inline_template("<%= '$::fqdn'.gsub('$::domain','').gsub(/[^a-z0-9]/i,'').to_i(36) % 256 %>"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment