Puppet Function: stdlib::fqdn_rotate
- Defined in:
-
lib/puppet/functions/stdlib/fqdn_rotate.rb
- Function type:
- Ruby 4.x API
Summary
Rotates an array or string a random number of times, combining the `fqdn` fact and an optional seed for repeatable randomness.
Overview
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/puppet/functions/stdlib/fqdn_rotate.rb', line 4
Puppet::Functions.create_function(:'stdlib::fqdn_rotate') do
dispatch :fqdn_rotate_string do
param 'String', :input
optional_repeated_param 'Variant[Integer,String]', :seeds
return_type 'String'
end
dispatch :fqdn_rotate_array do
param 'Array', :input
optional_repeated_param 'Variant[Integer,String]', :seeds
return_type 'Array'
end
def fqdn_rotate_array(input, *seeds)
return input if input.size <= 1
result = input.clone
require 'digest/md5'
seed = Digest::MD5.hexdigest([fqdn_fact, seeds].join(':')).hex
offset = Puppet::Util.deterministic_rand(seed, result.size).to_i
offset.times do
result.push result.shift
end
result
end
def fqdn_rotate_string(input, *seeds)
fqdn_rotate_array(input.chars, seeds).join
end
private
def fqdn_fact
closure_scope['facts']['networking']['fqdn']
end
end
|