Skip to content

Instantly share code, notes, and snippets.

@c33s
Forked from lavoiesl/uniqueid.pp
Created September 8, 2016 00:48
Show Gist options
  • Select an option

  • Save c33s/dcc0145a261eacabc9f200462c2c5cc6 to your computer and use it in GitHub Desktop.

Select an option

Save c33s/dcc0145a261eacabc9f200462c2c5cc6 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) %>")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment