To generate a unique integer ID in Puppet, we can use the hostname and convert is to base 10 using a erb inline template.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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) %>") | |
} |
No comments:
Post a Comment