less than 1 minute read

To generate a unique integer ID in Puppet, we can use the hostname and convert is to base 10 using a erb inline template.

1
2
3
4
5
6
7
8
9
10
11
12
# uniqueid.pp
#
# 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) %>")
}

View Gist