Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / README.md
1 # stdlib
2
3 #### Table of Contents
4
5 1. [Module Description - What the module does and why it is useful](#module-description)
6 1. [Setup - The basics of getting started with stdlib](#setup)
7 1. [Usage - Configuration options and additional functionality](#usage)
8 1. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
9     1. [Classes](#classes)
10     1. [Defined Types](#defined-types)
11     1. [Data Types](#data-types)
12     1. [Facts](#facts)
13     1. [Functions](#functions)
14 1. [Limitations - OS compatibility, etc.](#limitations)
15 1. [Development - Guide for contributing to the module](#development)
16 1. [Contributors](#contributors)
17
18 <a id="module-description"></a>
19 ## Module Description
20
21 This module provides a standard library of resources for Puppet modules. Puppet modules make heavy use of this standard library. The stdlib module adds the following resources to Puppet:
22
23  * Stages
24  * Facts
25  * Functions
26  * Defined types
27  * Data types
28  * Providers
29
30 > *Note:* As of version 3.7, Puppet Enterprise no longer includes the stdlib module. If you're running Puppet Enterprise, you should install the most recent release of stdlib for compatibility with Puppet modules.
31
32 <a id="setup"></a>
33 ## Setup
34
35 [Install](https://puppet.com/docs/puppet/latest/modules_installing.html) the stdlib module to add the functions, facts, and resources of this standard library to Puppet.
36
37 If you are authoring a module that depends on stdlib, be sure to [specify dependencies](https://puppet.com/docs/puppet/latest/modules_metadata.html#specifying-dependencies-in-modules) in your metadata.json.
38
39 <a id="usage"></a>
40 ## Usage
41
42 Most of stdlib's features are automatically loaded by Puppet. To use standardized run stages in Puppet, declare this class in your manifest with `include stdlib`.
43
44 When declared, stdlib declares all other classes in the module. The only other class currently included in the module is `stdlib::stages`.
45
46 The `stdlib::stages` class declares various run stages for deploying infrastructure, language runtimes, and application layers. The high level stages are (in order):
47
48   * setup
49   * main
50   * runtime
51   * setup_infra
52   * deploy_infra
53   * setup_app
54   * deploy_app
55   * deploy
56
57 Sample usage:
58
59 ```puppet
60 node default {
61   include stdlib
62   class { java: stage => 'runtime' }
63 }
64 ```
65
66 <a id="reference"></a>
67 ## Reference
68
69 * [Public classes](#public-classes)
70 * [Private classes](#private-classes)
71 * [Defined types](#defined-types)
72 * [Data types](#data-types)
73 * [Facts](#facts)
74 * [Functions](#functions)
75
76 <a id="classes"></a>
77 ### Classes
78
79 <a id="public-classes"></a>
80 #### Public classes
81
82 The `stdlib` class has no parameters.
83
84 <a id="private-classes"></a>
85 #### Private classes
86
87 * `stdlib::stages`: Manages a standard set of run stages for Puppet.
88
89 <a id="defined-types"></a>
90 ### Defined types
91
92 #### `file_line`
93
94 Ensures that a given line is contained within a file. The implementation matches the full line, including whitespace at the beginning and end. If the line is not contained in the given file, Puppet appends the line to the end of the file to ensure the desired state. Multiple resources can be declared to manage multiple lines in the same file.
95
96 Example:
97
98 ```puppet
99 file_line { 'sudo_rule':
100   path => '/etc/sudoers',
101   line => '%sudo ALL=(ALL) ALL',
102 }
103
104 file_line { 'sudo_rule_nopw':
105   path => '/etc/sudoers',
106   line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
107 }
108 ```
109
110 In the example above, Puppet ensures that both of the specified lines are contained in the file `/etc/sudoers`.
111
112 Match Example:
113
114 ```puppet
115 file_line { 'bashrc_proxy':
116   ensure => present,
117   path   => '/etc/bashrc',
118   line   => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
119   match  => '^export\ HTTP_PROXY\=',
120 }
121 ```
122
123 In the example above, `match` looks for a line beginning with 'export' followed by 'HTTP_PROXY' and replaces it with the value in line.
124
125 Match Example:
126
127 ```puppet
128 file_line { 'bashrc_proxy':
129   ensure             => present,
130   path               => '/etc/bashrc',
131   line               => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
132   match              => '^export\ HTTP_PROXY\=',
133   append_on_no_match => false,
134 }
135 ```
136
137 In this code example, `match` looks for a line beginning with export followed by 'HTTP_PROXY' and replaces it with the value in line. If a match is not found, then no changes are made to the file.
138
139 Examples of `ensure => absent`:
140
141 This type has two behaviors when `ensure => absent` is set.
142
143 The first is to set `match => ...` and `match_for_absence => true`. Match looks for a line beginning with 'export', followed by 'HTTP_PROXY', and then deletes it. If multiple lines match, an error is raised unless the `multiple => true` parameter is set.
144
145 The `line => ...` parameter in this example would be accepted but ignored.
146
147 For example:
148
149 ```puppet
150 file_line { 'bashrc_proxy':
151   ensure            => absent,
152   path              => '/etc/bashrc',
153   match             => '^export\ HTTP_PROXY\=',
154   match_for_absence => true,
155 }
156 ```
157
158 The second way of using `ensure => absent` is to specify a `line => ...` and no match. When ensuring lines are absent, the default behavior is to remove all lines matching. This behavior can't be disabled.
159
160 For example:
161
162 ```puppet
163 file_line { 'bashrc_proxy':
164   ensure => absent,
165   path   => '/etc/bashrc',
166   line   => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
167 }
168 ```
169
170
171 Encoding example:
172
173 ```puppet
174 file_line { "XScreenSaver":
175   ensure   => present,
176   path     => '/root/XScreenSaver'
177   line     => "*lock: 10:00:00",
178   match    => '^*lock:',
179   encoding => "iso-8859-1",
180 }
181 ```
182
183 Files with special characters that are not valid UTF-8 give the error message "Invalid byte sequence in UTF-8". In this case, determine the correct file encoding and specify it with the `encoding` attribute.
184
185 **Autorequires:** If Puppet is managing the file that contains the line being managed, the `file_line` resource autorequires that file.
186
187 **Parameters**
188
189 All parameters are optional, unless otherwise noted.
190
191 ##### `after`
192
193 Specifies the line after which Puppet adds any new lines using a regular expression. (Existing lines are added in place.)
194
195 Values: String containing a regex.
196
197 Default value: `undef`.
198
199 ##### `encoding`
200
201 Specifies the correct file encoding.
202
203 Values: String specifying a valid Ruby character encoding.
204
205 Default: 'UTF-8'.
206
207 ##### `ensure`
208
209 Specifies whether the resource is present.
210
211 Values: 'present', 'absent'.
212
213 Default value: 'present'.
214
215 ##### `line`
216
217 **Required.**
218
219 Sets the line to be added to the file located by the `path` parameter.
220
221 Values: String.
222
223 ##### `match`
224
225 Specifies a regular expression to compare against existing lines in the file; if a match is found, it is replaced rather than adding a new line.
226
227 Values: String containing a regex.
228
229 Default value: `undef`.
230
231
232 ##### `match_for_absence`
233
234 Specifies whether a match should be applied when `ensure => absent`. If set to `true` and match is set, the line that matches is deleted. If set to `false` (the default), match is ignored when `ensure => absent` and the value of `line` is used instead. Ignored when `ensure => present`.
235
236 Boolean.
237
238 Default value: `false`.
239
240 ##### `multiple`
241
242 Specifies whether `match` and `after` can change multiple lines. If set to `false`, allows file_line to replace only one line and raises an error if more than one will be replaced. If set to `true`, allows file_line to replace one or more lines.
243
244 Values: `true`, `false`.
245
246 Default value: `false`.
247
248
249 ##### `name`
250
251 Specifies the name to use as the identity of the resource. If you want the resource namevar to differ from the supplied `title` of the resource, specify it with `name`.
252
253 Values: String.
254
255 Default value: The value of the title.
256
257 ##### `path`
258
259 **Required.**
260
261 Specifies the file in which Puppet ensures the line specified by `line`.
262
263 Value: String specifying an absolute path to the file.
264
265 ##### `replace`
266
267 Specifies whether the resource overwrites an existing line that matches the `match` parameter when `line` does not otherwise exist.
268
269 If set to `false` and a line is found matching the `match` parameter, the line is not placed in the file.
270
271 Boolean.
272
273 Default value: `true`.
274
275 ##### `replace_all_matches_not_matching_line`
276
277 Replaces all lines matched by `match` parameter, even if `line` already exists in the file.
278
279 Default value: `false`.
280
281 <a id="data-types"></a>
282 ### Data types
283
284 #### `Stdlib::Absolutepath`
285
286 A strict absolute path type. Uses a variant of Unixpath and Windowspath types.
287
288 Acceptable input examples:
289
290 ```shell
291 /var/log
292 ```
293
294 ```shell
295 /usr2/username/bin:/usr/local/bin:/usr/bin:.
296 ```
297
298 ```shell
299 C:\\WINDOWS\\System32
300 ```
301
302 Unacceptable input example:
303
304 ```shell
305 ../relative_path
306 ```
307
308 #### `Stdlib::Ensure::Service`
309
310 Matches acceptable ensure values for service resources.
311
312 Acceptable input examples:
313
314 ```shell
315 stopped
316 running
317 ```
318
319 Unacceptable input example:
320
321 ```shell
322 true
323 false
324 ```
325
326 #### `Stdlib::Httpsurl`
327
328 Matches HTTPS URLs. It is a case insensitive match.
329
330 Acceptable input example:
331
332 ```shell
333 https://hello.com
334
335 HTTPS://HELLO.COM
336 ```
337
338 Unacceptable input example:
339
340 ```shell
341 httds://notquiteright.org`
342 ```
343
344 #### `Stdlib::Httpurl`
345
346 Matches both HTTPS and HTTP URLs. It is a case insensitive match.
347
348 Acceptable input example:
349
350 ```shell
351 https://hello.com
352
353 http://hello.com
354
355 HTTP://HELLO.COM
356 ```
357
358 Unacceptable input example:
359
360 ```shell
361 httds://notquiteright.org
362 ```
363
364 #### `Stdlib::MAC`
365
366 Matches MAC addresses defined in [RFC5342](https://tools.ietf.org/html/rfc5342).
367
368 #### `Stdlib::Unixpath`
369
370 Matches absolute paths on Unix operating systems.
371
372 Acceptable input example:
373
374 ```shell
375 /usr2/username/bin:/usr/local/bin:/usr/bin:
376
377 /var/tmp
378 ```
379
380 Unacceptable input example:
381
382 ```shell
383 C:/whatever
384
385 some/path
386
387 ../some/other/path
388 ```
389
390 #### `Stdlib::Filemode`
391
392 Matches octal file modes consisting of one to four numbers and symbolic file modes.
393
394 Acceptable input examples:
395
396 ```shell
397 0644
398 ```
399
400 ```shell
401 1777
402 ```
403
404 ```shell
405 a=Xr,g=w
406 ```
407
408 Unacceptable input examples:
409
410 ```shell
411 x=r,a=wx
412 ```
413
414 ```shell
415 0999
416 ```
417
418 #### `Stdlib::Windowspath`
419
420 Matches paths on Windows operating systems.
421
422 Acceptable input example:
423
424 ```shell
425 C:\\WINDOWS\\System32
426
427 C:\\
428
429 \\\\host\\windows
430 ```
431
432 Valid values: A windows filepath.
433
434 #### `Stdlib::Filesource`
435
436 Matches paths valid values for the source parameter of the Puppet file type.
437
438 Acceptable input example:
439
440 ```shell
441 http://example.com
442
443 https://example.com
444
445 file:///hello/bla
446 ```
447
448 Valid values: A filepath.
449
450 #### `Stdlib::Fqdn`
451
452 Matches paths on fully qualified domain name.
453
454 Acceptable input example:
455
456 ```shell
457 localhost
458
459 example.com
460
461 www.example.com
462 ```
463 Valid values: Domain name of a server.
464
465 #### `Stdlib::Host`
466
467 Matches a valid host which could be a valid ipv4, ipv6 or fqdn.
468
469 Acceptable input example:
470
471 ```shell
472 localhost
473
474 www.example.com
475
476 192.0.2.1
477 ```
478
479 Valid values: An IP address or domain name.
480
481 #### `Stdlib::Port`
482
483 Matches a valid TCP/UDP Port number.
484
485 Acceptable input examples:
486
487 ```shell
488 80
489
490 443
491
492 65000
493 ```
494
495 Valid values: An Integer.
496
497 #### `Stdlib::Port::Privileged`
498
499 Matches a valid TCP/UDP Privileged port i.e. < 1024.
500
501 Acceptable input examples:
502
503 ```shell
504 80
505
506 443
507
508 1023
509 ```
510
511 Valid values: A number less than 1024.
512
513 #### `Stdlib::Port::Unprivileged`
514
515 Matches a valid TCP/UDP Privileged port i.e. >= 1024.
516
517 Acceptable input examples:
518
519 ```shell
520 1024
521
522 1337
523
524 65000
525
526 ```
527
528 Valid values: A number more than or equal to 1024.
529
530 #### `Stdlib::Base32`
531
532 Matches paths a valid base32 string.
533
534 Acceptable input example:
535
536 ```shell
537 ASDASDDASD3453453
538
539 asdasddasd3453453=
540
541 ASDASDDASD3453453==
542 ```
543
544 Valid values: A base32 string.
545
546 #### `Stdlib::Base64`
547
548 Matches paths a valid base64 string.
549
550 Acceptable input example:
551
552 ```shell
553 asdasdASDSADA342386832/746+=
554
555 asdasdASDSADA34238683274/6+
556
557 asdasdASDSADA3423868327/46+==
558 ```
559
560 Valid values: A base64 string.
561
562 #### `Stdlib::Ipv4`
563
564 This type is no longer available. To make use of this functionality, use [Stdlib::IP::Address::V4](https://github.com/puppetlabs/puppetlabs-stdlib#stdlibipaddressv4).
565
566 #### `Stdlib::Ipv6`
567
568 This type is no longer available. To make use of this functionality, use  [Stdlib::IP::Address::V6](https://github.com/puppetlabs/puppetlabs-stdlib#stdlibipaddressv6).
569
570 #### `Stdlib::Ip_address`
571
572 This type is no longer available. To make use of this functionality, use  [Stdlib::IP::Address](https://github.com/puppetlabs/puppetlabs-stdlib#stdlibipaddress)
573
574 #### `Stdlib::IP::Address`
575
576 Matches any IP address, including both IPv4 and IPv6 addresses. It will match them either with or without an address prefix as used in CIDR format IPv4 addresses.
577
578 Examples:
579
580 ```
581 '127.0.0.1' =~ Stdlib::IP::Address                                # true
582 '10.1.240.4/24' =~ Stdlib::IP::Address                            # true
583 '52.10.10.141' =~ Stdlib::IP::Address                             # true
584 '192.168.1' =~ Stdlib::IP::Address                                # false
585 'FEDC:BA98:7654:3210:FEDC:BA98:7654:3210' =~ Stdlib::IP::Address  # true
586 'FF01:0:0:0:0:0:0:101' =~ Stdlib::IP::Address                     # true
587 ```
588
589 #### `Stdlib::IP::Address::V4`
590
591 Match any string consisting of an IPv4 address in the quad-dotted decimal format, with or without a CIDR prefix. It will not match any abbreviated form (for example, 192.168.1) because these are poorly documented and inconsistently supported.
592
593 Examples:
594
595 ```
596 '127.0.0.1' =~ Stdlib::IP::Address::V4                                # true
597 '10.1.240.4/24' =~ Stdlib::IP::Address::V4                            # true
598 '192.168.1' =~ Stdlib::IP::Address::V4                                # false
599 'FEDC:BA98:7654:3210:FEDC:BA98:7654:3210' =~ Stdlib::IP::Address::V4  # false
600 '12AB::CD30:192.168.0.1' =~ Stdlib::IP::Address::V4                   # false
601 ```
602
603 Valid values: An IPv4 address.
604
605 #### `Stdlib::IP::Address::V6`
606
607 Match any string consistenting of an IPv6 address in any of the documented formats in RFC 2373, with or without an address prefix.
608
609 Examples:
610
611 ```
612 '127.0.0.1' =~ Stdlib::IP::Address::V6                                # false
613 '10.1.240.4/24' =~ Stdlib::IP::Address::V6                            # false
614 'FEDC:BA98:7654:3210:FEDC:BA98:7654:3210' =~ Stdlib::IP::Address::V6  # true
615 'FF01:0:0:0:0:0:0:101' =~ Stdlib::IP::Address::V6                     # true
616 'FF01::101' =~ Stdlib::IP::Address::V6                                # true
617 ```
618
619 Valid values: An IPv6 address.
620
621 #### `Stdlib::IP::Address::Nosubnet`
622
623 Match the same things as the `Stdlib::IP::Address` alias, except it will not match an address that includes an address prefix (for example, it will match '192.168.0.6' but not '192.168.0.6/24').
624
625 Valid values: An IP address with no subnet.
626
627 #### `Stdlib::IP::Address::V4::CIDR`
628
629 Match an IPv4 address in the CIDR format. It will only match if the address contains an address prefix (for example, it will match '192.168.0.6/24'
630 but not '192.168.0.6').
631
632 Valid values: An IPv4 address with a CIDR provided eg: '192.186.8.101/105'. This will match anything inclusive of '192.186.8.101' to '192.168.8.105'.
633
634 #### `Stdlib::IP::Address::V4::Nosubnet`
635
636 Match an IPv4 address only if the address does not contain an address prefix (for example, it will match '192.168.0.6' but not '192.168.0.6/24').
637
638 Valid values: An IPv4 address with no subnet.
639
640 #### `Stdlib::IP::Address::V6::Full`
641
642 Match an IPv6 address formatted in the "preferred form" as documented in section 2.2 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt), with or without an address prefix as documented in section 2.3 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt).
643
644 #### `Stdlib::IP::Address::V6::Alternate`
645
646 Match an IPv6 address formatted in the "alternative form" allowing for representing the last two 16-bit pieces of the address with a quad-dotted decimal, as documented in section 2.2.1 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt). It will match addresses with or without an address prefix as documented in section 2.3 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt).
647
648 #### `Stdlib::IP::Address::V6::Compressed`
649
650 Match an IPv6 address which may contain `::` used to compress zeros as documented in section 2.2.2 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt). It will match addresses with or without an address prefix as documented in section 2.3 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt).
651
652 #### `Stdlib::IP::Address::V6::Nosubnet`
653
654 Alias to allow `Stdlib::IP::Address::V6::Nosubnet::Full`, `Stdlib::IP::Address::V6::Nosubnet::Alternate` and `Stdlib::IP::Address::V6::Nosubnet::Compressed`.
655
656 #### `Stdlib::IP::Address::V6::Nosubnet::Full`
657
658 Match an IPv6 address formatted in the "preferred form" as documented in section 2.2 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt). It will not match addresses with address prefix as documented in section 2.3 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt).
659
660 #### `Stdlib::IP::Address::V6::Nosubnet::Alternate`
661
662 Match an IPv6 address formatted in the "alternative form" allowing for representing the last two 16-bit pieces of the address with a quad-dotted decimal, as documented in section 2.2.1 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt). It will only match addresses without an address prefix as documented in section 2.3 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt).
663
664 #### `Stdlib::IP::Address::V6::Nosubnet::Compressed`
665
666 Match an IPv6 address which may contain `::` used to compress zeros as documented in section 2.2.2 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt). It will only match addresses without an address prefix as documented in section 2.3 of [RFC 2373](https://www.ietf.org/rfc/rfc2373.txt).
667
668 #### `Stdlib::IP::Address::V6::CIDR`
669
670 Match an IPv6 address in the CIDR format. It will only match if the address contains an address prefix (for example, it will match   'FF01:0:0:0:0:0:0:101/32', 'FF01::101/60', '::/0',
671 but not 'FF01:0:0:0:0:0:0:101', 'FF01::101', '::').
672
673 <a id="facts"></a>
674 ### Facts
675
676 #### `package_provider`
677
678 Returns the default provider Puppet uses to manage packages on this system.
679
680 #### `is_pe`
681
682 Returns whether Puppet Enterprise is installed. Does not report anything on platforms newer than PE 3.x.
683
684 #### `pe_version`
685
686 Returns the version of Puppet Enterprise installed. Does not report anything on platforms newer than PE 3.x.
687
688 #### `pe_major_version`
689
690 Returns the major version Puppet Enterprise that is installed. Does not report anything on platforms newer than PE 3.x.
691
692 #### `pe_minor_version`
693
694 Returns the minor version of Puppet Enterprise that is installed. Does not report anything on platforms newer than PE 3.x.
695
696 #### `pe_patch_version`
697
698 Returns the patch version of Puppet Enterprise that is installed.
699
700 #### `puppet_vardir`
701
702 Returns the value of the Puppet vardir setting for the node running Puppet or Puppet agent.
703
704 #### `puppet_environmentpath`
705
706 Returns the value of the Puppet environment path settings for the node running Puppet or Puppet agent.
707
708 #### `puppet_server`
709
710 Returns the Puppet agent's `server` value, which is the hostname of the Puppet master with which the agent should communicate.
711
712 #### `root_home`
713
714 Determines the root home directory.
715
716 Determines the root home directory, which depends on your operating system. Generally this is '/root'.
717
718 #### `service_provider`
719
720 Returns the default provider Puppet uses to manage services on this system
721
722 <a id="functions"></a>
723 ### Functions
724
725 #### `abs`
726
727 **Deprecated:** This function has been replaced with a built-in [`abs`](https://puppet.com/docs/puppet/latest/function.html#abs) function as of Puppet 6.0.0.
728
729 Returns the absolute value of a number. For example, '-34.56' becomes '34.56'.
730
731 Argument: A single argument of either an integer or float value.
732
733 *Type*: rvalue.
734
735 #### `any2array`
736
737 Converts any object to an array containing that object. Converts empty argument lists are to empty arrays. Hashes are converted to arrays of alternating keys and values. Arrays are not touched.
738
739 Since Puppet 5.0.0, you can create new values of almost any datatype using the type system â€” you can use the built-in [`Array.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-array-and-tuple) function to create a new array:
740
741     $hsh = {'key' => 42, 'another-key' => 100}
742     notice(Array($hsh))
743
744 Would notice `[['key', 42], ['another-key', 100]]`
745
746 The array data type also has a special mode to "create an array if not already an array":
747
748     notice(Array({'key' => 42, 'another-key' => 100}, true))
749
750 Would notice `[{'key' => 42, 'another-key' => 100}]`, as the `true` flag prevents the hash from being transformed into an array.
751
752 *Type*: rvalue.
753
754 #### `any2bool`
755
756 Converts any object to a Boolean:
757
758 * Strings such as 'Y', 'y', '1', 'T', 't', 'TRUE', 'yes', 'true' return `true`.
759 * Strings such as '0', 'F', 'f', 'N', 'n', 'FALSE', 'no', 'false' return `false`.
760 * Booleans return their original value.
761 * A number (or a string representation of a number) greater than 0 returns `true`, otherwise `false`.
762 * An undef value returns `false`.
763 * Anything else returns `true`.
764
765 See the built-in [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean)
766
767 *Type*: rvalue.
768
769 #### `assert_private`
770
771 Sets the current class or definition as private. Calling the class or defined type from outside the current module fails.
772
773 For example, `assert_private()` called in class `foo::bar` outputs the following message if class is called from outside module `foo`: `Class foo::bar is private.`
774
775 To specify the error message you want to use:
776
777 ```puppet
778 assert_private("You're not supposed to do that!")
779 ```
780
781 *Type*: statement.
782
783 #### `base64`
784
785 Converts a string to and from base64 encoding. Requires an `action` ('encode', 'decode') and either a plain or base64-encoded `string`, and an optional `method` ('default', 'strict', 'urlsafe').
786
787 For backward compatibility, `method` is set as `default` if not specified.
788
789 > **Note**: This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
790
791 Since Puppet 4.8.0, the `Binary` data type can be used to produce base 64 encoded strings.
792
793 See the built-in [`String.new`](https://puppet.com/docs/puppet/latest/function.html#binary-value-to-string) and [`Binary.new`](https://puppet.com/docs/puppet/latest/function.html#creating-a-binary) functions.
794
795 See the built-in [`binary_file`](https://puppet.com/docs/puppet/latest/function.html#binary_file) function for reading a file with binary (non UTF-8) content.
796
797     # encode a string as if it was binary
798     $encodestring = String(Binary('thestring', '%s'))
799     # decode a Binary assuming it is an UTF-8 String
800     $decodestring = String(Binary("dGhlc3RyaW5n"), "%s")
801
802 **Examples:**
803
804 ```puppet
805 base64('encode', 'hello')
806 base64('encode', 'hello', 'default')
807 # return: "aGVsbG8=\n"
808
809 base64('encode', 'hello', 'strict')
810 # return: "aGVsbG8="
811
812 base64('decode', 'aGVsbG8=')
813 base64('decode', 'aGVsbG8=\n')
814 base64('decode', 'aGVsbG8=', 'default')
815 base64('decode', 'aGVsbG8=\n', 'default')
816 base64('decode', 'aGVsbG8=', 'strict')
817 # return: "hello"
818
819 base64('encode', 'https://puppetlabs.com', 'urlsafe')
820 # return: "aHR0cHM6Ly9wdXBwZXRsYWJzLmNvbQ=="
821
822 base64('decode', 'aHR0cHM6Ly9wdXBwZXRsYWJzLmNvbQ==', 'urlsafe')
823 # return: "https://puppetlabs.com"
824 ```
825
826 *Type*: rvalue.
827
828 #### `basename`
829
830 Returns the `basename` of a path. An optional argument strips the extension. For example:
831
832 ```puppet
833 basename('/path/to/a/file.ext')            => 'file.ext'
834 basename('relative/path/file.ext')         => 'file.ext'
835 basename('/path/to/a/file.ext', '.ext')    => 'file'
836 ```
837
838 *Type*: rvalue.
839
840 #### `bool2num`
841
842 Converts a Boolean to a number. Converts values:
843
844 * `false`, 'f', '0', 'n', and 'no' to 0.
845 * `true`, 't', '1', 'y', and 'yes' to 1.
846
847 Argument: a single Boolean or string as an input.
848
849 Since Puppet 5.0.0, you can create values for almost any data type using the type system â€” you can use the built-in [`Numeric.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-numeric), [`Integer.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-integer), and [`Float.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-float)
850 functions to convert to numeric values:
851
852     notice(Integer(false)) # Notices 0
853     notice(Float(true))    # Notices 1.0
854
855 *Type*: rvalue.
856
857 #### `bool2str`
858
859 Converts a Boolean to a string using optionally supplied arguments. The optional second and third arguments represent what true and false are converted to respectively. If only one argument is given, it is converted from a Boolean to a string containing `true` or `false`.
860
861 *Examples:*
862
863 ```puppet
864 bool2str(true)                    => `true`
865 bool2str(true, 'yes', 'no')       => 'yes'
866 bool2str(false, 't', 'f')         => 'f'
867 ```
868
869 Arguments: Boolean.
870
871 Since Puppet 5.0.0, you can create new values for almost any
872 data type using the type system â€” you can use the built-in
873 [`String.new`](https://puppet.com/docs/puppet/latest/function.html#boolean-to-string)
874 function to convert to String, with many different format options:
875
876     notice(String(false))         # Notices 'false'
877     notice(String(true))          # Notices 'true'
878     notice(String(false, '%y'))   # Notices 'yes'
879     notice(String(true, '%y'))    # Notices 'no'
880
881 *Type*: rvalue.
882
883 #### `camelcase`
884
885 **Deprecated:** This function has been replaced with a built-in [`camelcase`](https://puppet.com/docs/puppet/latest/function.html#camelcase) function as of Puppet 6.0.0.
886
887 Converts the case of a string or all strings in an array to CamelCase (mixed case).
888
889 Arguments: Either an array or string. Returns the same type of argument as it received, but in CamelCase form.
890
891 *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
892
893  *Type*: rvalue.
894
895 #### `capitalize`
896
897 **Deprecated:** This function has been replaced with a built-in [`capitalize`](https://puppet.com/docs/puppet/latest/function.html#capitalize) function as of Puppet 6.0.0.
898
899 Capitalizes the first character of a string or array of strings and lowercases the remaining characters of each string.
900
901 Arguments: either a single string or an array as an input. *Type*: rvalue.
902
903 *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
904
905 #### `ceiling`
906
907 **Deprecated:** This function has been replaced with a built-in [`ceiling`](https://puppet.com/docs/puppet/latest/function.html#ceiling) function as of Puppet 6.0.0.
908
909 Returns the smallest integer greater than or equal to the argument.
910
911 Arguments: A single numeric value.
912
913 *Type*: rvalue.
914
915 #### `chomp`
916
917 **Deprecated:** This function has been replaced with a built-in [`chomp`](https://puppet.com/docs/puppet/latest/function.html#chomp) function as of Puppet 6.0.0.
918
919 Removes the record separator from the end of a string or an array of strings; for example, 'hello\n' becomes 'hello'.
920
921 Arguments: a single string or array.
922
923 *Type*: rvalue.
924
925 #### `chop`
926
927 **Deprecated:** This function has been replaced with a built-in [`chop`](https://puppet.com/docs/puppet/latest/function.html#chop) function as of Puppet 6.0.0.
928
929 Returns a new string with the last character removed. If the string ends with '\r\n', both characters are removed. Applying `chop` to an empty string returns an empty string. To only remove record separators, use the `chomp` function.
930
931 Arguments: A string or an array of strings as input.
932
933 *Type*: rvalue.
934
935 #### `clamp`
936
937 Keeps value within the range [Min, X, Max] by sort based on integer value (parameter order doesn't matter). Strings are converted and compared numerically. Arrays of values are flattened into a list for further handling. For example:
938
939   * `clamp('24', [575, 187])` returns 187.
940   * `clamp(16, 88, 661)` returns 88.
941   * `clamp([4, 3, '99'])` returns 4.
942
943 Arguments: strings, arrays, or numerics.
944
945 Since Puppet 6.0.0, you can use built-in functions to get the same result:
946
947     [$minval, $maxval, $value_to_clamp].sort[1]
948
949 *Type*: rvalue.
950
951 #### `concat`
952
953 Appends the contents of multiple arrays onto the first array given. For example:
954
955   * `concat(['1','2','3'],'4')` returns ['1','2','3','4'].
956   * `concat(['1','2','3'],'4',['5','6','7'])` returns ['1','2','3','4','5','6','7'].
957
958 Since Puppet 4.0, you can use the `+` operator for concatenation of arrays and merge of hashes, and the `<<` operator for appending:
959
960     ['1','2','3'] + ['4','5','6'] + ['7','8','9'] # returns ['1','2','3','4','5','6','7','8','9']
961     [1, 2, 3] << 4 # returns [1, 2, 3, 4]
962     [1, 2, 3] << [4, 5] # returns [1, 2, 3, [4, 5]]
963
964 *Type*: rvalue.
965
966 #### `convert_base`
967
968 Converts a given integer or base 10 string representing an integer to a specified base, as a string. For example:
969
970   * `convert_base(5, 2)` results in: '101'
971   * `convert_base('254', '16')` results in: 'fe'
972
973 Since Puppet 4.5.0, you can do this with the built-in [`String.new`](https://puppet.com/docs/puppet/latest/function.html#integer-to-string) function, with various formatting options:
974
975     $binary_repr = String(5, '%b') # results in "101"
976     $hex_repr = String(254, '%x')  # results in "fe"
977     $hex_repr = String(254, '%#x') # results in "0xfe"
978
979 #### `count`
980
981 Takes an array as the first argument and an optional second argument.
982 It counts the number of elements in an array that is equal to the second argument.
983 If called with only an array, it counts the number of elements that are not nil/undef/empty-string.
984
985 > **Note**: Equality is tested with a Ruby method. It is subject to what Ruby considers
986 to be equal. For strings, equality is case sensitive.
987
988 In Puppet core, counting is done using a combination of the built-in functions
989 [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) (since Puppet 4.0.0) and
990 [`length`](https://puppet.com/docs/puppet/latest/function.html#length) (since Puppet 5.5.0, before that in stdlib).
991
992 This example shows counting values that are not `undef`:
993
994     notice([42, "hello", undef].filter |$x| { $x =~ NotUndef }.length)
995
996 Would notice 2.
997
998 *Type*: rvalue.
999
1000 #### `deep_merge`
1001
1002 Recursively merges two or more hashes together and returns the resulting hash.
1003
1004 ```puppet
1005 $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }
1006 $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } }
1007 $merged_hash = deep_merge($hash1, $hash2)
1008 ```
1009
1010 The resulting hash is equivalent to:
1011
1012 ```puppet
1013 $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } }
1014 ```
1015
1016 If there is a duplicate key that is a hash, they are recursively merged. If there is a duplicate key that is not a hash, the key in the rightmost hash takes precedence.
1017
1018 *Type*: rvalue.
1019
1020 #### `defined_with_params`
1021
1022 Takes a resource reference and an optional hash of attributes. Returns `true` if a resource with the specified attributes has already been added to the catalog. Returns `false` otherwise.
1023
1024 ```puppet
1025 user { 'dan':
1026   ensure => present,
1027 }
1028
1029 if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
1030   user { 'dan': ensure => present, }
1031 }
1032 ```
1033
1034 *Type*: rvalue.
1035
1036 #### `delete`
1037
1038 Deletes all instances of a given element from an array, substring from a string, or key from a hash.
1039
1040 For example:
1041
1042 * `delete(['a','b','c','b'], 'b')` returns ['a','c'].
1043 * `delete('abracadabra', 'bra')` returns 'acada'.
1044 * `delete({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1}.
1045 * `delete(['ab', 'b'], 'b')` returns ['ab'].
1046
1047 Since Puppet 4.0.0, the minus (`-`) operator deletes values from arrays and deletes keys from a hash:
1048
1049     ['a', 'b', 'c', 'b'] - 'b'
1050     # would return ['a', 'c']
1051
1052     {'a'=>1,'b'=>2,'c'=>3} - ['b','c'])
1053     # would return {'a' => '1'}
1054
1055 You can perform a global delete from a string with the built-in
1056 [`regsubst`](https://puppet.com/docs/puppet/latest/function.html#regsubst) function.
1057
1058     'abracadabra'.regsubst(/bra/, '', 'G')
1059     # would return 'acada'
1060
1061 In general, the built-in
1062 [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function
1063 can filter out entries from arrays and hashes based on a combination of keys and values.
1064
1065 *Type*: rvalue.
1066
1067 #### `delete_at`
1068
1069 Deletes a determined indexed value from an array.
1070
1071 For example: `delete_at(['a','b','c'], 1)` returns ['a','c'].
1072
1073 Since Puppet 4, this can be done with the built-in
1074 [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function:
1075
1076     ['a', 'b', 'c'].filter |$pos, $val | { $pos != 1 } # returns ['a', 'c']
1077     ['a', 'b', 'c', 'd'].filter |$pos, $val | { $pos % 2 != 0 } # returns ['b', 'd']
1078
1079 Or, if you want to delete from the beginning or the end of the array â€” or from both ends at the same time â€” use the slice operator `[ ]`:
1080
1081     $array[0, -1] # the same as all the values
1082     $array[2, -1] # all but the first 2 elements
1083     $array[0, -3] # all but the last 2 elements
1084     $array[1, -2] # all but the first and last element
1085
1086 *Type*: rvalue.
1087
1088 #### `delete_regex`
1089
1090 Deletes all instances of a given element from an array or hash that match a provided regular expression. A string is treated as a one-item array.
1091
1092 *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
1093
1094 For example:
1095
1096 * `delete_regex(['a','b','c','b'], 'b')` returns ['a','c'].
1097 * `delete_regex({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1}.
1098 * `delete_regex(['abf', 'ab', 'ac'], '^ab.*')` returns ['ac'].
1099 * `delete_regex(['ab', 'b'], 'b')` returns ['ab'].
1100
1101 Since Puppet 4.0.0, do the equivalent with the built-in
1102 [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function:
1103
1104     ["aaa", "aba", "aca"].filter |$val| { $val !~ /b/ }
1105     # Would return: ['aaa', 'aca']
1106
1107 *Type*: rvalue.
1108
1109 #### `delete_values`
1110
1111 Deletes all instances of a given value from a hash.
1112
1113 For example:
1114
1115 * `delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')` returns {'a'=>'A','c'=>'C','B'=>'D'}
1116
1117 Since Puppet 4.0.0, do the equivalent with the built-in
1118 [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function:
1119
1120     $array.filter |$val| { $val != 'B' }
1121     $hash.filter |$key, $val| { $val != 'B' }
1122
1123 *Type*: rvalue.
1124
1125 #### `delete_undef_values`
1126
1127 Deletes all instances of the `undef` value from an array or hash.
1128
1129 For example:
1130
1131 * `$hash = delete_undef_values({a=>'A', b=>'', c=>`undef`, d => false})` returns {a => 'A', b => '', d => false}.
1132
1133 Since Puppet 4.0.0, do the equivalent with the built-in
1134 [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function:
1135
1136     $array.filter |$val| { $val =~ NotUndef }
1137     $hash.filter |$key, $val| { $val =~ NotUndef }
1138
1139 *Type*: rvalue.
1140
1141 #### `deprecation`
1142
1143 Prints deprecation warnings and logs a warning once for a given key:
1144
1145 ```puppet
1146 deprecation(key, message)
1147 ```
1148
1149 Arguments:
1150
1151 * A string specifying the key: To keep the number of messages low during the lifetime of a Puppet process, only one message per key is logged.
1152 * A string specifying the message: the text to be logged.
1153
1154 *Type*: Statement.
1155
1156 **Settings that affect `deprecation`**
1157
1158 Other settings in Puppet affect the stdlib `deprecation` function:
1159
1160 * [`disable_warnings`](https://puppet.com/docs/puppet/latest/configuration.html#disablewarnings)
1161 * [`max_deprecations`](https://puppet.com/docs/puppet/latest/configuration.html#maxdeprecations)
1162 * [`strict`](https://puppet.com/docs/puppet/latest/configuration.html#strict):
1163
1164     * `error`: Fails immediately with the deprecation message
1165     * `off`: Output emits no messages.
1166     * `warning`: Logs all warnings. This is the default setting.
1167
1168 * The environment variable `STDLIB_LOG_DEPRECATIONS`
1169
1170   Specifies whether or not to log deprecation warnings. This is especially useful for automated tests to avoid flooding your logs before you are ready to migrate.
1171
1172   This variable is Boolean, with the following effects:
1173
1174   * `true`: Functions log a warning.
1175   * `false`: No warnings are logged.
1176   * No value set: Puppet 4 emits warnings, but Puppet 3 does not.
1177
1178 #### `difference`
1179
1180 Returns the difference between two arrays. The returned array is a copy of the original array, removing any items that also appear in the second array.
1181
1182 For example:
1183
1184 * `difference(["a","b","c"],["b","c","d"])` returns ["a"].
1185
1186 Since Puppet 4, the minus (`-`) operator in the Puppet language does the same:
1187
1188     ['a', 'b', 'c'] - ['b', 'c', 'd']
1189     # would return ['a']
1190
1191 *Type*: rvalue.
1192
1193 #### `dig`
1194
1195 **Deprecated:** This function has been replaced with a built-in [`dig`](https://puppet.com/docs/puppet/latest/function.html#dig) function as of Puppet 4.5.0. Use [`dig44()`](#dig44) for backwards compatibility or use the new version.
1196
1197 Retrieves a value within multiple layers of hashes and arrays via an array of keys containing a path. The function goes through the structure by each path component and tries to return the value at the end of the path.
1198
1199 In addition to the required path argument, the function accepts the default argument. It is returned if the path is not correct, if no value was found, or if any other error has occurred.
1200
1201 ```ruby
1202 $data = {
1203   'a' => {
1204     'b' => [
1205       'b1',
1206       'b2',
1207       'b3',
1208     ]
1209   }
1210 }
1211
1212 $value = dig($data, ['a', 'b', 2])
1213 # $value = 'b3'
1214
1215 # with all possible options
1216 $value = dig($data, ['a', 'b', 2], 'not_found')
1217 # $value = 'b3'
1218
1219 # using the default value
1220 $value = dig($data, ['a', 'b', 'c', 'd'], 'not_found')
1221 # $value = 'not_found'
1222 ```
1223
1224 1. **$data** The data structure we are working with.
1225 2. **['a', 'b', 2]** The path array.
1226 3. **'not_found'** The default value. It is returned if nothing is found.
1227
1228 Default value: `undef`.
1229
1230 *Type*: rvalue.
1231
1232 #### `dig44`
1233
1234 Retrieves a value within multiple layers of hashes and arrays via an array of keys containing a path. The function goes through the structure by each path component and tries to return the value at the end of the path.
1235
1236 In addition to the required path argument, the function accepts the default argument. It is returned if the path is incorrect, if no value was found, or if any other error has occurred.
1237
1238 ```ruby
1239 $data = {
1240   'a' => {
1241     'b' => [
1242       'b1',
1243       'b2',
1244       'b3',
1245     ]
1246   }
1247 }
1248
1249 $value = dig44($data, ['a', 'b', 2])
1250 # $value = 'b3'
1251
1252 # with all possible options
1253 $value = dig44($data, ['a', 'b', 2], 'not_found')
1254 # $value = 'b3'
1255
1256 # using the default value
1257 $value = dig44($data, ['a', 'b', 'c', 'd'], 'not_found')
1258 # $value = 'not_found'
1259 ```
1260
1261 *Type*: rvalue.
1262
1263 1. **$data** The data structure we are working with.
1264 2. **['a', 'b', 2]** The path array.
1265 3. **'not_found'** The default value. It will be returned if nothing is found.
1266    (optional, defaults to `undef`)
1267
1268 #### `dirname`
1269
1270 Returns the `dirname` of a path. For example, `dirname('/path/to/a/file.ext')` returns '/path/to/a'.
1271
1272 *Type*: rvalue.
1273
1274 #### `dos2unix`
1275
1276 Returns the Unix version of the given string. Very useful when using a File resource with a cross-platform template.
1277
1278 ```puppet
1279 file { $config_file:
1280   ensure  => file,
1281   content => dos2unix(template('my_module/settings.conf.erb')),
1282 }
1283 ```
1284
1285 See also [unix2dos](#unix2dos).
1286
1287 *Type*: rvalue.
1288
1289 #### `downcase`
1290
1291 **Deprecated:** This function has been replaced with a built-in [`downcase`](https://puppet.com/docs/puppet/latest/function.html#downcase) function as of Puppet 6.0.0.
1292
1293 Converts the case of a string or of all strings in an array to lowercase.
1294
1295 *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
1296
1297 *Type*: rvalue.
1298
1299 #### `empty`
1300
1301 **Deprecated:** This function has been replaced with a built-in [`empty`](https://puppet.com/docs/puppet/latest/function.html#empty) function as of Puppet 5.5.0.
1302
1303 Returns `true` if the argument is an array or hash that contains no elements, or an empty string. Returns `false` when the argument is a numerical value.
1304
1305 *Type*: rvalue.
1306
1307 #### `enclose_ipv6`
1308
1309 Takes an array of IP addresses and encloses the ipv6 addresses with square brackets.
1310
1311 *Type*: rvalue.
1312
1313 #### `ensure_packages`
1314
1315 Takes a list of packages in an array or hash and installs them only if they don't already exist. Optionally takes a hash as a second parameter to be passed as the third argument to the `ensure_resource()` or `ensure_resources()` function.
1316
1317 *Type*: statement.
1318
1319 For an array:
1320
1321 ```puppet
1322 ensure_packages(['ksh','openssl'], {'ensure' => 'present'})
1323 ```
1324
1325 For a hash:
1326
1327 ```puppet
1328 ensure_packages({'ksh' => { ensure => '20120801-1' } ,  'mypackage' => { source => '/tmp/myrpm-1.0.0.x86_64.rpm', provider => "rpm" }}, {'ensure' => 'present'})
1329 ```
1330
1331 #### `ensure_resource`
1332
1333 Takes a resource type, title, and a hash of attributes that describe the resource(s).
1334
1335 ```
1336 user { 'dan':
1337   ensure => present,
1338 }
1339 ```
1340
1341 This example only creates the resource if it does not already exist:
1342
1343   `ensure_resource('user', 'dan', {'ensure' => 'present' })`
1344
1345 If the resource already exists, but does not match the specified parameters, this function attempts to recreate the resource, leading to a duplicate resource definition error.
1346
1347 An array of resources can also be passed in, and each will be created with the type and parameters specified if it doesn't already exist.
1348
1349 `ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})`
1350
1351 *Type*: statement.
1352
1353 #### `ensure_resources`
1354
1355 Creates resource declarations from a hash, but doesn't conflict with resources that are already declared.
1356
1357 Specify a resource type and title and a hash of attributes that describe the resource(s).
1358
1359 ```puppet
1360 user { 'dan':
1361   gid => 'mygroup',
1362   ensure => present,
1363 }
1364
1365 ensure_resources($user)
1366 ```
1367
1368 Pass in a hash of resources. Any listed resources that don't already exist will be created with the type and parameters specified:
1369
1370     ensure_resources('user', {'dan' => { gid => 'mygroup', uid => '600' } ,  'alex' => { gid => 'mygroup' }}, {'ensure' => 'present'})
1371
1372 From Hiera backend:
1373
1374 ```yaml
1375 userlist:
1376   dan:
1377     gid: 'mygroup'
1378     uid: '600'
1379   alex:
1380     gid: 'mygroup'
1381 ```
1382
1383 ```puppet
1384 ensure_resources('user', hiera_hash('userlist'), {'ensure' => 'present'})
1385 ```
1386
1387 #### `stdlib::extname`
1388
1389 Returns the Extension (the Portion of Filename in Path starting from the last Period).
1390
1391 Example usage:
1392
1393 ```puppet
1394 stdlib::extname('test.rb')       => '.rb'
1395 stdlib::extname('a/b/d/test.rb') => '.rb'
1396 stdlib::extname('test')          => ''
1397 stdlib::extname('.profile')      => ''
1398 ```
1399
1400 *Type*: rvalue.
1401
1402 #### `fact`
1403
1404 Return the value of a given fact. Supports the use of dot-notation for referring to structured facts. If a fact requested does not exist, returns Undef.
1405
1406 Example usage:
1407
1408 ```puppet
1409 fact('kernel')
1410 fact('osfamily')
1411 fact('os.architecture')
1412 ```
1413
1414 Array indexing:
1415
1416 ```puppet
1417 $first_processor  = fact('processors.models.0')
1418 $second_processor = fact('processors.models.1')
1419 ```
1420
1421 Fact containing a "." in the fact name:
1422
1423 ```puppet
1424 fact('vmware."VRA.version"')
1425 ```
1426
1427 #### `flatten`
1428
1429 **Deprecated:** This function has been replaced with a built-in [`flatten`](https://puppet.com/docs/puppet/latest/function.html#flatten) function as of Puppet 5.5.0.
1430
1431 Flattens deeply nested arrays and returns a single flat array as a result.
1432
1433 For example, `flatten(['a', ['b', ['c']]])` returns ['a','b','c'].
1434
1435 *Type*: rvalue.
1436
1437 #### `floor`
1438
1439 **Deprecated:** This function has been replaced with a built-in [`floor`](https://puppet.com/docs/puppet/latest/function.html#floor) function as of Puppet 6.0.0.
1440
1441 Returns the largest integer less than or equal to the argument.
1442
1443 Arguments: A single numeric value.
1444
1445 *Type*: rvalue.
1446
1447 #### `fqdn_rand_string`
1448
1449 Generates a random alphanumeric string, combining the `$fqdn` fact and an optional seed for repeatable randomness. Optionally, you can specify a character set for the function (defaults to alphanumeric).
1450
1451 *Usage:*
1452
1453 ```puppet
1454 fqdn_rand_string(LENGTH, [CHARSET], [SEED])
1455 ```
1456
1457 *Examples:*
1458
1459 ```puppet
1460 fqdn_rand_string(10)
1461 fqdn_rand_string(10, 'ABCDEF!@#$%^')
1462 fqdn_rand_string(10, '', 'custom seed')
1463 ```
1464
1465 Arguments:
1466
1467 * An integer, specifying the length of the resulting string.
1468 * Optionally, a string specifying the character set.
1469 * Optionally, a string specifying the seed for repeatable randomness.
1470
1471 *Type*: rvalue.
1472
1473 #### `fqdn_rotate`
1474
1475 Rotates an array or string a random number of times, combining the `$fqdn` fact and an optional seed for repeatable randomness.
1476
1477 *Usage:*
1478
1479 ```puppet
1480 fqdn_rotate(VALUE, [SEED])
1481 ```
1482
1483 *Examples:*
1484
1485 ```puppet
1486 fqdn_rotate(['a', 'b', 'c', 'd'])
1487 fqdn_rotate('abcd')
1488 fqdn_rotate([1, 2, 3], 'custom seed')
1489 ```
1490
1491 *Type*: rvalue.
1492
1493 #### `fqdn_uuid`
1494
1495 Returns a [RFC 4122](https://tools.ietf.org/html/rfc4122) valid version 5 UUID based on an FQDN string under the DNS namespace:
1496
1497   * fqdn_uuid('puppetlabs.com') returns '9c70320f-6815-5fc5-ab0f-debe68bf764c'
1498   * fqdn_uuid('google.com') returns '64ee70a4-8cc1-5d25-abf2-dea6c79a09c8'
1499
1500 *Type*: rvalue.
1501
1502 #### `get_module_path`
1503
1504 Returns the absolute path of the specified module for the current environment.
1505
1506 ```puppet
1507 $module_path = get_module_path('stdlib')
1508 ```
1509
1510 Since Puppet 5.4.0, the built-in [`module_directory`](https://puppet.com/docs/puppet/latest/function.html#module_directory) function does the same thing and will return the path to the first module found, if given multiple values or an array.
1511
1512 *Type*: rvalue.
1513
1514 #### `getparam`
1515 Returns the value of a resource's parameter.
1516
1517 Arguments: A resource reference and the name of the parameter.
1518
1519 > Note: User defined resource types are evaluated lazily.
1520
1521 *Examples:*
1522
1523 ```puppet
1524 # define a resource type with a parameter
1525 define example_resource($param) {
1526 }
1527
1528 # declare an instance of that type
1529 example_resource { "example_resource_instance":
1530     param => "'the value we are getting in this example''"
1531 }
1532
1533 # Because of order of evaluation, a second definition is needed
1534 # that will be evaluated after the first resource has been declared
1535 #
1536 define example_get_param {
1537   # This will notice the value of the parameter
1538   notice(getparam(Example_resource["example_resource_instance"], "param"))
1539 }
1540
1541 # Declare an instance of the second resource type - this will call notice
1542 example_get_param { 'show_notify': }
1543 ```
1544
1545 Would notice: 'the value we are getting in this example'
1546
1547 Since Puppet 4.0.0, you can get a parameter value by using its data type
1548 and the [ ] operator. The example below is equivalent to a call to getparam():
1549
1550 ```puppet
1551 Example_resource['example_resource_instance']['param']
1552 ```
1553
1554 #### `getvar`
1555 **Deprecated:** This function has been replaced with a built-in [`getvar`](https://puppet.com/docs/puppet/latest/function.html#getvar)
1556 function as of Puppet 6.0.0. The new version also supports digging into a structured value.
1557
1558 Looks up a variable in a remote namespace.
1559
1560 For example:
1561
1562 ```puppet
1563 $foo = getvar('site::data::foo')
1564 # Equivalent to $foo = $site::data::foo
1565 ```
1566
1567 This is useful if the namespace itself is stored in a string:
1568
1569 ```puppet
1570 $datalocation = 'site::data'
1571 $bar = getvar("${datalocation}::bar")
1572 # Equivalent to $bar = $site::data::bar
1573 ```
1574
1575 *Type*: rvalue.
1576
1577 #### `glob`
1578
1579 Returns an array of strings of paths matching path patterns.
1580
1581 Arguments: A string or an array of strings specifying path patterns.
1582
1583 ```puppet
1584 $confs = glob(['/etc/**/*.conf', '/opt/**/*.conf'])
1585 ```
1586
1587 *Type*: rvalue.
1588
1589 #### `grep`
1590
1591 Searches through an array and returns any elements that match the provided regular expression.
1592
1593 For example, `grep(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['aaa','aaaddd'].
1594
1595 Since Puppet 4.0.0, the built-in [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function does the "same" â€” as any logic can be used to filter, as opposed to just regular expressions:
1596
1597     ['aaa', 'bbb', 'ccc', 'aaaddd']. filter |$x| { $x =~ 'aaa' }
1598
1599 *Type*: rvalue.
1600
1601 #### `has_interface_with`
1602
1603 Returns a Boolean based on kind and value:
1604
1605   * macaddress
1606   * netmask
1607   * ipaddress
1608   * network
1609
1610 *Examples:*
1611
1612 ```puppet
1613 has_interface_with("macaddress", "x:x:x:x:x:x")
1614 has_interface_with("ipaddress", "127.0.0.1")    => true
1615 ```
1616
1617 If no kind is given, then the presence of the interface is checked:
1618
1619 ```puppet
1620 has_interface_with("lo")                        => true
1621 ```
1622
1623 *Type*: rvalue.
1624
1625 #### `has_ip_address`
1626
1627 Returns `true` if the client has the requested IP address on some interface. This function iterates through the `interfaces` fact and checks the `ipaddress_IFACE` facts, performing a simple string comparison.
1628
1629 Arguments: A string specifying an IP address.
1630
1631 *Type*: rvalue.
1632
1633 #### `has_ip_network`
1634
1635 Returns `true` if the client has an IP address within the requested network. This function iterates through the `interfaces` fact and checks the `network_IFACE` facts, performing a simple string comparision.
1636
1637 Arguments: A string specifying an IP address.
1638
1639 *Type*: rvalue.
1640
1641 #### `has_key`
1642 **Deprecated:** This function has been replaced with the built-in operator `in`.
1643
1644 Determines if a hash has a certain key value.
1645
1646 *Example*:
1647
1648 ```
1649 $my_hash = {'key_one' => 'value_one'}
1650 if has_key($my_hash, 'key_two') {
1651   notice('we will not reach here')
1652 }
1653 if has_key($my_hash, 'key_one') {
1654   notice('this will be printed')
1655 }
1656 ```
1657
1658 Since Puppet 4.0.0, this can be achieved in the Puppet language with the following equivalent expression:
1659
1660     $my_hash = {'key_one' => 'value_one'}
1661     if 'key_one' in $my_hash {
1662       notice('this will be printed')
1663     }
1664
1665 *Type*: rvalue.
1666
1667 #### `hash`
1668
1669 **Deprecated:** This function has been replaced with the built-in ability to create a new value of almost any
1670 data type - see the built-in [`Hash.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-hash-and-struct) function
1671 in Puppet.
1672
1673 Converts an array into a hash.
1674
1675 For example (deprecated), `hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}.
1676
1677 For example (built-in), `Hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}.
1678
1679 *Type*: rvalue.
1680
1681 #### `intersection`
1682
1683 Returns an array an intersection of two.
1684
1685 For example, `intersection(["a","b","c"],["b","c","d"])` returns ["b","c"].
1686
1687 *Type*: rvalue.
1688
1689 #### `is_a`
1690
1691 Boolean check to determine whether a variable is of a given data type. This is equivalent to the `=~` type checks. This function is available only in Puppet 4, or in Puppet 3 with the "future" parser.
1692
1693 ```
1694 foo = 3
1695 $bar = [1,2,3]
1696 $baz = 'A string!'
1697
1698 if $foo.is_a(Integer) {
1699   notify  { 'foo!': }
1700 }
1701 if $bar.is_a(Array) {
1702   notify { 'bar!': }
1703 }
1704 if $baz.is_a(String) {
1705   notify { 'baz!': }
1706 }
1707 ```
1708
1709 * See the [the Puppet type system](https://puppet.com/docs/puppet/latest/lang_data.html) for more information about types.
1710 * See the [`assert_type()`](https://puppet.com/docs/puppet/latest/function.html#asserttype) function for flexible ways to assert the type of a value.
1711
1712 #### `is_absolute_path`
1713
1714 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1715
1716 Returns `true` if the given path is absolute.
1717
1718 *Type*: rvalue.
1719
1720 #### `is_array`
1721
1722 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1723
1724 Returns `true` if the variable passed to this function is an array.
1725
1726 *Type*: rvalue.
1727
1728 #### `is_bool`
1729
1730 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1731
1732 Returns `true` if the variable passed to this function is a Boolean.
1733
1734 *Type*: rvalue.
1735
1736 #### `is_domain_name`
1737
1738 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1739
1740 Returns `true` if the string passed to this function is a syntactically correct domain name.
1741
1742 *Type*: rvalue.
1743
1744 #### `is_email_address`
1745
1746 Returns true if the string passed to this function is a valid email address.
1747
1748 *Type*: rvalue.
1749
1750
1751 #### `is_float`
1752
1753 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1754
1755 Returns `true` if the variable passed to this function is a float.
1756
1757 *Type*: rvalue.
1758
1759 #### `is_function_available`
1760
1761 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1762
1763 Accepts a string as an argument and determines whether the Puppet runtime has access to a function by that name. It returns `true` if the function exists, `false` if not.
1764
1765 *Type*: rvalue.
1766
1767 #### `is_hash`
1768
1769 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1770
1771 Returns `true` if the variable passed to this function is a hash.
1772
1773 *Type*: rvalue.
1774
1775 #### `is_integer`
1776
1777 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1778
1779 Returns `true` if the variable returned to this string is an integer.
1780
1781 *Type*: rvalue.
1782
1783 #### `is_ip_address`
1784
1785 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1786
1787 Returns `true` if the string passed to this function is a valid IP address.
1788
1789 *Type*: rvalue.
1790
1791 #### `is_ipv6_address`
1792
1793 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1794
1795 Returns `true` if the string passed to this function is a valid IPv6 address.
1796
1797 *Type*: rvalue.
1798
1799 #### `is_ipv4_address`
1800
1801 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1802
1803 Returns `true` if the string passed to this function is a valid IPv4 address.
1804
1805 *Type*: rvalue.
1806
1807 #### `is_mac_address`
1808
1809 Returns `true` if the string passed to this function is a valid MAC address.
1810
1811 *Type*: rvalue.
1812
1813 #### `is_numeric`
1814
1815 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1816
1817 Returns `true` if the variable passed to this function is a number.
1818
1819 *Type*: rvalue.
1820
1821 #### `is_string`
1822
1823 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
1824
1825 Returns `true` if the variable passed to this function is a string.
1826
1827 *Type*: rvalue.
1828
1829 #### `join`
1830
1831 **Deprecated:** This function has been replaced with a built-in [`join`](https://puppet.com/docs/puppet/latest/function.html#join) function as of Puppet 5.5.0.
1832
1833 Joins an array into a string using a separator. For example, `join(['a','b','c'], ",")` results in: "a,b,c".
1834
1835 *Type*: rvalue.
1836
1837 #### `join_keys_to_values`
1838
1839 Joins each key of a hash to that key's corresponding value with a separator, returning the result as strings.
1840
1841 If a value is an array, the key is prefixed to each element. The return value is a flattened array.
1842
1843 For example, `join_keys_to_values({'a'=>1,'b'=>[2,3]}, " is ")` results in ["a is 1","b is 2","b is 3"].
1844
1845 Since Puppet 5.0.0, there is more control over the formatting (including indentations and line breaks, delimiters around arrays and hash entries, between key/values in hash entries, and individual
1846 formatting of values in the array) - see the
1847 built-in [`String.new`](https://docs.puppet.com/puppet/latest/function.html#conversion-to-string) function and its formatting options for `Array` and `Hash`.
1848
1849 *Type*: rvalue.
1850
1851 #### `keys`
1852
1853 **Deprecated:** This function has been replaced with a built-in [`keys`](https://puppet.com/docs/puppet/latest/function.html#keys) function as of Puppet 5.5.0.
1854
1855 Returns the keys of a hash as an array.
1856
1857 *Type*: rvalue.
1858
1859 #### `length`
1860
1861 **Deprecated:** This function has been replaced with a built-in [`length`](https://puppet.com/docs/puppet/latest/function.html#length) function as of Puppet 5.5.0.
1862
1863 Returns the length of a given string, array or hash. Replaces the deprecated `size()` function.
1864
1865 *Type*: rvalue.
1866
1867 #### `loadyaml`
1868
1869 Loads a YAML file containing an array, string, or hash, and returns the data in the corresponding native data type.
1870
1871 For example:
1872
1873 ```puppet
1874 $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
1875 ```
1876
1877 The second parameter is returned if the file was not found or could not be parsed.
1878
1879 For example:
1880
1881 ```puppet
1882 $myhash = loadyaml('no-file.yaml', {'default'=>'value'})
1883 ```
1884
1885 *Type*: rvalue.
1886
1887 #### `loadjson`
1888
1889 Loads a JSON file containing an array, string, or hash, and returns the data in the corresponding native data type.
1890
1891 For example:
1892
1893 The first parameter can be an absolute file path, or a URL.
1894
1895 ```puppet
1896 $myhash = loadjson('/etc/puppet/data/myhash.json')
1897 ```
1898
1899 The second parameter is returned if the file was not found or could not be parsed.
1900
1901 For example:
1902
1903 ```puppet
1904   $myhash = loadjson('no-file.json', {'default'=>'value'})
1905   ```
1906
1907 *Type*: rvalue.
1908
1909 #### `load_module_metadata`
1910
1911 Loads the metadata.json of a target module. Can be used to determine module version and authorship for dynamic support of modules.
1912
1913 ```puppet
1914 $metadata = load_module_metadata('archive')
1915 notify { $metadata['author']: }
1916 ```
1917
1918 When a module's metadata file is absent, the catalog compilation fails. To avoid this failure, do the following:
1919
1920 ```
1921 $metadata = load_module_metadata('mysql', true)
1922 if empty($metadata) {
1923   notify { "This module does not have a metadata.json file.": }
1924 }
1925 ```
1926
1927 *Type*: rvalue.
1928
1929 #### `lstrip`
1930
1931 **Deprecated:** This function has been replaced with a built-in [`lstrip`](https://puppet.com/docs/puppet/latest/function.html#lstrip) function as of Puppet 6.0.0.
1932
1933 Strips spaces to the left of a string.
1934
1935 *Type*: rvalue.
1936
1937 #### `max`
1938
1939 **Deprecated:** This function has been replaced with a built-in [`max`](https://puppet.com/docs/puppet/latest/function.html#max) function as of Puppet 6.0.0.
1940
1941 Returns the highest value of all arguments. Requires at least one argument.
1942
1943 Arguments: A numeric or a string representing a number.
1944
1945 *Type*: rvalue.
1946
1947 #### `member`
1948
1949 This function determines if a variable is a member of an array. The variable can be a string, an array, or a fixnum.
1950
1951 For example, `member(['a','b'], 'b')` and `member(['a','b','c'], ['b','c'])` return `true`, while `member(['a','b'], 'c')` and `member(['a','b','c'], ['c','d'])` return `false`.
1952
1953 *Note*: This function does not support nested arrays. If the first argument contains nested arrays, it will not recurse through them.
1954
1955 Since Puppet 4.0.0, you can perform the same in the Puppet language. For single values,
1956 use the operator `in`:
1957
1958     'a' in ['a', 'b']  # true
1959
1960 And for arrays, use the operator `-` to compute a diff:
1961
1962     ['d', 'b'] - ['a', 'b', 'c'] == []  # false because 'd' is not subtracted
1963     ['a', 'b'] - ['a', 'b', 'c'] == []  # true because both 'a' and 'b' are subtracted
1964
1965 Also note that since Puppet 5.2.0, the general form to test the content of an array or hash is to use the built-in [`any`](https://puppet.com/docs/puppet/latest/function.html#any) and [`all`](https://puppet.com/docs/puppet/latest/function.html#all) functions.
1966
1967 *Type*: rvalue.
1968
1969 #### `merge`
1970
1971 Merges two or more hashes together and returns the resulting hash.
1972
1973 *Example*:
1974
1975 ```puppet
1976 $hash1 = {'one' => 1, 'two' => 2}
1977 $hash2 = {'two' => 'dos', 'three' => 'tres'}
1978 $merged_hash = merge($hash1, $hash2)
1979 # The resulting hash is equivalent to:
1980 # $merged_hash =  {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
1981 ```
1982
1983 When there is a duplicate key, the key in the rightmost hash takes precedence.
1984
1985 Since Puppet 4.0.0, you can use the + operator to achieve the same merge.
1986
1987     $merged_hash = $hash1 + $hash2
1988
1989 *Type*: rvalue.
1990
1991 #### `min`
1992
1993 **Deprecated:** This function has been replaced with a built-in [`min`](https://puppet.com/docs/puppet/latest/function.html#min) function as of Puppet 6.0.0.
1994
1995 Returns the lowest value of all arguments. Requires at least one argument.
1996
1997 Arguments: A numeric or a string representing a number.
1998
1999 *Type*: rvalue.
2000
2001 #### `num2bool`
2002
2003 Converts a number, or a string representation of a number, into a true Boolean.
2004 Zero or anything non-numeric becomes `false`.
2005 Numbers greater than zero become `true`.
2006
2007 Since Puppet 5.0.0, the same can be achieved with the Puppet type system.
2008 See the [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean)
2009 function in Puppet for the many available type conversions.
2010
2011     Boolean(0) # false
2012     Boolean(1) # true
2013
2014 *Type*: rvalue.
2015
2016 #### `os_version_gte`
2017
2018 Checks to see if the OS version is at least a certain version. Note that only the major version is taken into account.
2019
2020 Example usage:
2021 ```
2022   if os_version_gte('Debian', '9') { }
2023   if os_version_gte('Ubuntu', '18.04') { }
2024 ```
2025
2026 Returns:
2027   - Boolean(0) # When OS is below the given version.
2028   - Boolean(1) # When OS is equal to or greater than the given version.
2029
2030 #### `parsejson`
2031
2032 Converts a string of JSON into the correct Puppet structure (as a hash, array, string, integer, or a combination of such).
2033
2034 Arguments:
2035 * The JSON string to convert, as a first argument.
2036 * Optionally, the result to return if conversion fails, as a second error.
2037
2038 *Type*: rvalue.
2039
2040 #### `parseyaml`
2041
2042 Converts a string of YAML into the correct Puppet structure.
2043
2044 Arguments:
2045 * The YAML string to convert, as a first argument.
2046 * Optionally, the result to return if conversion fails, as a second error.
2047
2048 *Type*: rvalue.
2049
2050 #### `pick`
2051
2052 From a list of values, returns the first value that is not undefined or an empty string. Takes any number of arguments, and raises an error if all values are undefined or empty.
2053
2054 ```puppet
2055 $real_jenkins_version = pick($::jenkins_version, '1.449')
2056 ```
2057
2058 *Type*: rvalue.
2059
2060 #### `pick_default`
2061
2062 Returns the first value in a list of values. Unlike the `pick()` function, `pick_default()` does not fail if all arguments are empty. This allows it to use an empty value as default.
2063
2064 *Type*: rvalue.
2065
2066 #### `prefix`
2067
2068 Applies a prefix to all elements in an array, or to the keys in a hash.
2069
2070 For example:
2071
2072 * `prefix(['a','b','c'], 'p')` returns ['pa','pb','pc'].
2073 * `prefix({'a'=>'b','b'=>'c','c'=>'d'}, 'p')` returns {'pa'=>'b','pb'=>'c','pc'=>'d'}.
2074
2075 Since Puppet 4.0.0, modify values in array by using the built-in [`map`](https://docs.puppet.com/puppet/latest/function.html#map) function.
2076 This example does the same as the first example above:
2077
2078         ['a', 'b', 'c'].map |$x| { "p${x}" }
2079
2080 *Type*: rvalue.
2081
2082 #### `pry`
2083
2084 Invokes a pry debugging session in the current scope object. Useful for debugging manifest code at specific points during a compilation. Should be used only when running `puppet apply` or running a Puppet master in the foreground. Requires the `pry` gem to be installed in Puppet's rubygems.
2085
2086 *Examples:*
2087
2088 ```puppet
2089 pry()
2090 ```
2091
2092 In a pry session, useful commands include:
2093
2094 * Run `catalog` to see the contents currently compiling catalog.
2095 * Run `cd catalog` and `ls` to see catalog methods and instance variables.
2096 * Run `@resource_table` to see the current catalog resource table.
2097
2098 #### `pw_hash`
2099
2100 Hashes a password using the crypt function. Provides a hash usable on most POSIX systems.
2101
2102 The first argument to this function is the password to hash. If it is `undef` or an empty string, this function returns `undef`.
2103
2104 The second argument to this function is which type of hash to use. It will be converted into the appropriate crypt(3) hash specifier. Valid hash types are:
2105
2106 |Hash type            |Specifier|
2107 |---------------------|---------|
2108 |MD5                  |1        |
2109 |SHA-256              |5        |
2110 |SHA-512 (recommended)|6        |
2111
2112 The third argument to this function is the salt to use.
2113
2114 This function uses the Puppet master's implementation of crypt(3). If your environment contains several different operating systems, ensure that they are compatible before using this function.
2115
2116 *Type*: rvalue.
2117
2118 *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
2119
2120 #### `range`
2121
2122 Extrapolates a range as an array when given in the form of '(start, stop)'. For example, `range("0", "9")` returns [0,1,2,3,4,5,6,7,8,9]. Zero-padded strings are converted to integers automatically, so `range("00", "09")` returns [0,1,2,3,4,5,6,7,8,9].
2123
2124 Non-integer strings are accepted:
2125
2126 * `range("a", "c")` returns ["a","b","c"].
2127 * `range("host01", "host10")` returns ["host01", "host02", ..., "host09", "host10"].
2128
2129 You must explicitly include trailing zeros, or the underlying Ruby function fails.
2130
2131 Passing a third argument causes the generated range to step by that interval. For example:
2132
2133 * `range("0", "9", "2")` returns ["0","2","4","6","8"].
2134
2135 > Note: The Puppet language supports `Integer` and `Float` ranges by using the type system. They are suitable for iterating a given number of times.
2136
2137 See the built-in [`step`](https://docs.puppet.com/puppet/latest/function.html#step) function in Puppet for skipping values.
2138
2139     Integer[0, 9].each |$x| { notice($x) } # notices 0, 1, 2, ... 9
2140
2141 *Type*: rvalue.
2142
2143 #### `regexpescape`
2144
2145 Regexp escape a string or array of strings. Requires either a single string or an array as an input.
2146
2147 *Type*: rvalue.
2148
2149 #### `reject`
2150
2151 Searches through an array and rejects all elements that match the provided regular expression.
2152
2153 For example, `reject(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['bbb','ccc'].
2154
2155 Since Puppet 4.0.0, the same is true with the built-in [`filter`](https://docs.puppet.com/puppet/latest/function.html#filter) function in Puppet.
2156 The equivalent of the stdlib `reject` function:
2157
2158     ['aaa','bbb','ccc','aaaddd'].filter |$x| { $x !~ /aaa/ }
2159
2160 *Type*: rvalue.
2161
2162 #### `reverse`
2163
2164 Reverses the order of a string or array.
2165
2166 > *Note*: The same can be done with the built-in [`reverse_each`](https://docs.puppet.com/puppet/latest/function.html#reverse_each) function in Puppet.
2167
2168
2169 #### `round`
2170
2171 **Deprecated:** This function has been replaced with a built-in [`round`](https://puppet.com/docs/puppet/latest/function.html#round) function as of Puppet 6.0.0.
2172
2173 Rounds a number to the nearest integer.
2174
2175 *Type*: rvalue.
2176
2177 #### `rstrip`
2178
2179 **Deprecated:** This function has been replaced with a built-in [`rstrip`](https://puppet.com/docs/puppet/latest/function.html#rstrip) function as of Puppet 6.0.0.
2180
2181 Strips spaces to the right of the string.
2182
2183 *Type*: rvalue.
2184
2185 #### `seeded_rand`
2186
2187 Takes an integer max value and a string seed value and returns a repeatable random integer smaller than max. Similar to `fqdn_rand`, but does not add node specific data to the seed.
2188
2189 *Type*: rvalue.
2190
2191 #### `seeded_rand_string`
2192
2193 Generates a consistent (based on seed value) random string. Useful for generating matching passwords for different hosts.
2194
2195 #### `shell_escape`
2196
2197 Escapes a string so that it can be safely used in a Bourne shell command line. Note that the resulting string should be used unquoted and is not intended for use in either double or single quotes. This function behaves the same as Ruby's `Shellwords.shellescape()` function; see the [Ruby documentation](http://ruby-doc.org/stdlib-2.3.0/libdoc/shellwords/rdoc/Shellwords.html#method-c-shellescape).
2198
2199 For example:
2200
2201 ```puppet
2202 shell_escape('foo b"ar') => 'foo\ b\"ar'
2203 ```
2204
2205 *Type*: rvalue.
2206
2207 #### `shell_join`
2208
2209 Builds a command line string from a given array of strings. Each array item is escaped for Bourne shell. All items are then joined together, with a single space in between. This function behaves the same as Ruby's `Shellwords.shelljoin()` function; see the [Ruby documentation](http://ruby-doc.org/stdlib-2.3.0/libdoc/shellwords/rdoc/Shellwords.html#method-c-shelljoin).
2210
2211 For example:
2212
2213 ```puppet
2214 shell_join(['foo bar', 'ba"z']) => 'foo\ bar ba\"z'
2215 ```
2216
2217 *Type*: rvalue.
2218
2219 #### `shell_split`
2220
2221 Splits a string into an array of tokens. This function behaves the same as Ruby's `Shellwords.shellsplit()` function; see the [ruby documentation](http://ruby-doc.org/stdlib-2.3.0/libdoc/shellwords/rdoc/Shellwords.html#method-c-shellsplit).
2222
2223 *Example:*
2224
2225 ```puppet
2226 shell_split('foo\ bar ba\"z') => ['foo bar', 'ba"z']
2227 ```
2228
2229 *Type*: rvalue.
2230
2231 #### `shuffle`
2232
2233 Randomizes the order of a string or array elements.
2234
2235 *Type*: rvalue.
2236
2237 #### `size`
2238
2239 **Deprecated:** This function has been replaced with a built-in [`size`](https://puppet.com/docs/puppet/latest/function.html#size) function as of Puppet 6.0.0 (`size` is now an alias for `length`).
2240
2241 Returns the number of elements in a string, an array or a hash. This function will be deprecated in a future release. For Puppet 4, use the `length` function.
2242
2243 *Type*: rvalue.
2244
2245 #### `sprintf_hash`
2246
2247 **Deprecated:** The same functionality can be achieved with the built-in [`sprintf`](https://docs.puppet.com/puppet/latest/function.html#sprintf) function as of Puppet 4.10.10 and 5.3.4. This function will be removed in a future release.
2248
2249 Performs printf-style formatting with named references of text.
2250
2251 The first parameter is a format string describing how to format the rest of the parameters in the hash. See Ruby documentation for [`Kernel::sprintf`](https://ruby-doc.org/core-2.4.2/Kernel.html#method-i-sprintf) for details about this function.
2252
2253 For example:
2254
2255 ```puppet
2256 $output = sprintf_hash('String: %<foo>s / number converted to binary: %<number>b',
2257                        { 'foo' => 'a string', 'number' => 5 })
2258 # $output = 'String: a string / number converted to binary: 101'
2259 ```
2260
2261 *Type*: rvalue
2262
2263 #### `sort`
2264
2265 **Deprecated:** This function has been replaced with a built-in [`sort`](https://puppet.com/docs/puppet/latest/function.html#sort) function as of Puppet 6.0.0.
2266
2267 Sorts strings and arrays lexically.
2268
2269 *Type*: rvalue.
2270
2271 > *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
2272
2273 #### `squeeze`
2274
2275 Replaces consecutive repeats (such as 'aaaa') in a string with a single character. Returns a new string.
2276
2277 *Type*: rvalue.
2278
2279 #### `str2bool`
2280
2281 Converts certain strings to a Boolean. This attempts to convert strings that contain the values '1', 'true', 't', 'y', or 'yes' to `true`. Strings that contain values '0', 'false', 'f', 'n', or 'no', or that are an empty string or undefined are converted to `false`. Any other value causes an error. These checks are case insensitive.
2282
2283 Since Puppet 5.0.0, the same can be achieved with the Puppet type system.
2284 See the [`Boolean.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-boolean)
2285 function in Puppet for the many available type conversions.
2286
2287     Boolean('false'), Boolean('n'), Boolean('no') # all false
2288     Boolean('true'), Boolean('y'), Boolean('yes') # all true
2289
2290 *Type*: rvalue.
2291
2292 #### `str2saltedsha512`
2293
2294 Converts a string to a salted-SHA512 password hash, used for OS X versions 10.7 or greater. Returns a hex version of a salted-SHA512 password hash, which can be inserted into Puppet manifests as a valid password attribute.
2295
2296 *Type*: rvalue.
2297
2298 > *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
2299
2300 #### `strftime`
2301
2302 **Deprecated:** This function has been replaced with a built-in [`strftime`](https://puppet.com/docs/puppet/latest/function.html#strftime) function as of Puppet 4.8.0.
2303
2304 Returns formatted time.
2305
2306 For example, `strftime("%s")` returns the time since Unix epoch, and `strftime("%Y-%m-%d")` returns the date.
2307
2308 Arguments: A string specifying the time in `strftime` format. See the Ruby [strftime](https://ruby-doc.org/core-2.1.9/Time.html#method-i-strftime) documentation for details.
2309
2310 *Type*: rvalue.
2311
2312 > *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
2313
2314 *Format:*
2315
2316 * `%a`: The abbreviated weekday name ('Sun')
2317 * `%A`: The full weekday name ('Sunday')
2318 * `%b`: The abbreviated month name ('Jan')
2319 * `%B`: The full month name ('January')
2320 * `%c`: The preferred local date and time representation
2321 * `%C`: Century (20 in 2009)
2322 * `%d`: Day of the month (01..31)
2323 * `%D`: Date (%m/%d/%y)
2324 * `%e`: Day of the month, blank-padded ( 1..31)
2325 * `%F`: Equivalent to %Y-%m-%d (the ISO 8601 date format)
2326 * `%h`: Equivalent to %b
2327 * `%H`: Hour of the day, 24-hour clock (00..23)
2328 * `%I`: Hour of the day, 12-hour clock (01..12)
2329 * `%j`: Day of the year (001..366)
2330 * `%k`: Hour, 24-hour clock, blank-padded ( 0..23)
2331 * `%l`: Hour, 12-hour clock, blank-padded ( 0..12)
2332 * `%L`: Millisecond of the second (000..999)
2333 * `%m`: Month of the year (01..12)
2334 * `%M`: Minute of the hour (00..59)
2335 * `%n`: Newline (\n)
2336 * `%N`: Fractional seconds digits, default is 9 digits (nanosecond)
2337   * `%3N`: Millisecond (3 digits)
2338   * `%6N`: Microsecond (6 digits)
2339   * `%9N`: Nanosecond (9 digits)
2340 * `%p`: Meridian indicator ('AM' or 'PM')
2341 * `%P`: Meridian indicator ('am' or 'pm')
2342 * `%r`: Time, 12-hour (same as %I:%M:%S %p)
2343 * `%R`: Time, 24-hour (%H:%M)
2344 * `%s`: Number of seconds since the Unix epoch, 1970-01-01 00:00:00 UTC.
2345 * `%S`: Second of the minute (00..60)
2346 * `%t`: Tab character ( )
2347 * `%T`: Time, 24-hour (%H:%M:%S)
2348 * `%u`: Day of the week as a decimal, Monday being 1. (1..7)
2349 * `%U`: Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
2350 * `%v`: VMS date (%e-%b-%Y)
2351 * `%V`: Week number of year according to ISO 8601 (01..53)
2352 * `%W`: Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
2353 * `%w`: Day of the week (Sunday is 0, 0..6)
2354 * `%x`: Preferred representation for the date alone, no time
2355 * `%X`: Preferred representation for the time alone, no date
2356 * `%y`: Year without a century (00..99)
2357 * `%Y`: Year with century
2358 * `%z`: Time zone as hour offset from UTC (for example +0900)
2359 * `%Z`: Time zone name
2360 * `%%`: Literal '%' character
2361
2362 #### `strip`
2363
2364 **Deprecated:** This function has been replaced with a built-in [`strip`](https://puppet.com/docs/puppet/latest/function.html#strip) function as of Puppet 6.0.0.
2365
2366 Removes leading and trailing whitespace from a string or from every string inside an array. For example, `strip("    aaa   ")` results in "aaa".
2367
2368 *Type*: rvalue.
2369
2370 #### `suffix`
2371
2372 Applies a suffix to all elements in an array or to all keys in a hash.
2373
2374 For example:
2375
2376 * `suffix(['a','b','c'], 'p')` returns ['ap','bp','cp'].
2377 * `suffix({'a'=>'b','b'=>'c','c'=>'d'}, 'p')` returns {'ap'=>'b','bp'=>'c','cp'=>'d'}.
2378
2379 Note that since Puppet 4.0.0, you can modify values in an array using the built-in [`map`](https://docs.puppet.com/puppet/latest/function.html#map) function. This example does the same as the first example above:
2380
2381     ['a', 'b', 'c'].map |$x| { "${x}p" }
2382
2383 *Type*: rvalue.
2384
2385 #### `swapcase`
2386
2387 Swaps the existing case of a string. For example, `swapcase("aBcD")` results in "AbCd".
2388
2389 *Type*: rvalue.
2390
2391 > *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
2392
2393 #### `time`
2394
2395 Returns the current Unix epoch time as an integer.
2396
2397 For example, `time()` returns something like '1311972653'.
2398
2399 Since Puppet 4.8.0, the Puppet language has the data types `Timestamp` (a point in time) and `Timespan` (a duration). The following example is equivalent to calling `time()` without any arguments:
2400
2401     Timestamp()
2402
2403 *Type*: rvalue.
2404
2405 #### `to_bytes`
2406
2407 Converts the argument into bytes.
2408
2409 For example, "4 kB" becomes "4096".
2410
2411 Arguments: A single string.
2412
2413 *Type*: rvalue.
2414
2415 #### `to_json`
2416
2417 Converts input into a JSON String.
2418
2419 For example, `{ "key" => "value" }` becomes `{"key":"value"}`.
2420
2421 *Type*: rvalue.
2422
2423 #### `to_json_pretty`
2424
2425 Converts input into a pretty JSON String.
2426
2427 For example, `{ "key" => "value" }` becomes `{\n  \"key\": \"value\"\n}`.
2428
2429 *Type*: rvalue.
2430
2431 #### `to_yaml`
2432
2433 Converts input into a YAML String.
2434
2435 For example, `{ "key" => "value" }` becomes `"---\nkey: value\n"`.
2436
2437 *Type*: rvalue.
2438
2439 #### `try_get_value`
2440
2441 **Deprecated:** Replaced by `dig()`.
2442
2443 Retrieves a value within multiple layers of hashes and arrays.
2444
2445 Arguments:
2446
2447 * A string containing a path, as the first argument. Provide this argument as a string of hash keys or array indexes starting with zero and separated by the path separator character (default "/"). This function goes through the structure by each path component and tries to return the value at the end of the path.
2448
2449 * A default argument as a second argument. This argument is returned if the path is not correct, if no value was found, or if any other error has occurred.
2450 * The path separator character as a last argument.
2451
2452 ```ruby
2453 $data = {
2454   'a' => {
2455     'b' => [
2456       'b1',
2457       'b2',
2458       'b3',
2459     ]
2460   }
2461 }
2462
2463 $value = try_get_value($data, 'a/b/2')
2464 # $value = 'b3'
2465
2466 # with all possible options
2467 $value = try_get_value($data, 'a/b/2', 'not_found', '/')
2468 # $value = 'b3'
2469
2470 # using the default value
2471 $value = try_get_value($data, 'a/b/c/d', 'not_found')
2472 # $value = 'not_found'
2473
2474 # using custom separator
2475 $value = try_get_value($data, 'a|b', [], '|')
2476 # $value = ['b1','b2','b3']
2477 ```
2478
2479 1. **$data** The data structure we are working with.
2480 2. **'a/b/2'** The path string.
2481 3. **'not_found'** The default value. It will be returned if nothing is found.
2482    (optional, defaults to *`undef`*)
2483 4. **'/'** The path separator character.
2484    (optional, defaults to *'/'*)
2485
2486 *Type*: rvalue.
2487
2488 #### `type3x`
2489
2490 **Deprecated:** This function will be removed in a future release.
2491
2492 Returns a string description of the type of a given value. The type can be a string, array, hash, float, integer, or Boolean. For Puppet 4, use the new type system instead.
2493
2494 Arguments:
2495
2496 * string
2497 * array
2498 * hash
2499 * float
2500 * integer
2501 * Boolean
2502
2503 *Type*: rvalue.
2504
2505 #### `type_of`
2506
2507 This function is provided for backwards compatibility, but the built-in [type() function](https://puppet.com/docs/puppet/latest/function.html#type) provided by Puppet is preferred.
2508
2509 Returns the literal type of a given value. Requires Puppet 4. Useful for comparison of types with `<=` such as in `if type_of($some_value) <= Array[String] { ... }` (which is equivalent to `if $some_value =~ Array[String] { ... }`).
2510
2511 *Type*: rvalue.
2512
2513 #### `union`
2514
2515 Returns a union of two or more arrays, without duplicates.
2516
2517 For example, `union(["a","b","c"],["b","c","d"])` returns ["a","b","c","d"].
2518
2519 *Type*: rvalue.
2520
2521 #### `unique`
2522
2523 Removes duplicates from strings and arrays.
2524
2525 For example, `unique("aabbcc")` returns 'abc', and `unique(["a","a","b","b","c","c"])` returns ["a","b","c"].
2526
2527 *Type*: rvalue.
2528
2529 #### `unix2dos`
2530
2531 Returns the DOS version of a given string. Useful when using a File resource with a cross-platform template.
2532
2533 *Type*: rvalue.
2534
2535 ```puppet
2536 file { $config_file:
2537   ensure  => file,
2538   content => unix2dos(template('my_module/settings.conf.erb')),
2539 }
2540 ```
2541
2542 See also [dos2unix](#dos2unix).
2543
2544 #### `upcase`
2545
2546 **Deprecated:** This function has been replaced with a built-in [`upcase`](https://puppet.com/docs/puppet/latest/function.html#upcase) function as of Puppet 6.0.0.
2547
2548 Converts an object, array, or hash of objects to uppercase. Objects to be converted must respond to upcase.
2549
2550 For example, `upcase('abcd')` returns 'ABCD'.
2551
2552 *Type*: rvalue.
2553
2554 *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
2555
2556 #### `uriescape`
2557
2558 URLEncodes a string or array of strings.
2559
2560 Arguments: Either a single string or an array of strings.
2561
2562 *Type*: rvalue.
2563
2564 > *Note:* This function is an implementation of a Ruby class and might not be UTF8 compatible. To ensure compatibility, use this function with Ruby 2.4.0 or greater.
2565
2566 #### `validate_absolute_path`
2567
2568 Validates that a given string represents an absolute path in the filesystem. Works for Windows and Unix style paths.
2569
2570 The following values pass:
2571
2572 ```puppet
2573 $my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet'
2574 validate_absolute_path($my_path)
2575 $my_path2 = '/var/lib/puppet'
2576 validate_absolute_path($my_path2)
2577 $my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet','C:/Program Files/Puppet Labs/Puppet']
2578 validate_absolute_path($my_path3)
2579 $my_path4 = ['/var/lib/puppet','/usr/share/puppet']
2580 validate_absolute_path($my_path4)
2581 ```
2582
2583 The following values fail, causing compilation to terminate:
2584
2585 ```puppet
2586 validate_absolute_path(true)
2587 validate_absolute_path('../var/lib/puppet')
2588 validate_absolute_path('var/lib/puppet')
2589 validate_absolute_path([ 'var/lib/puppet', '/var/foo' ])
2590 validate_absolute_path([ '/var/lib/puppet', 'var/foo' ])
2591 $undefined = `undef`
2592 validate_absolute_path($undefined)
2593 ```
2594
2595 *Type*: statement.
2596
2597 #### `validate_array`
2598
2599 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
2600
2601 Validates that all passed values are array data structures. Terminates catalog compilation if any value fails this check.
2602
2603 The following values pass:
2604
2605 ```puppet
2606 $my_array = [ 'one', 'two' ]
2607 validate_array($my_array)
2608 ```
2609
2610 The following values fail, causing compilation to terminate:
2611
2612 ```puppet
2613 validate_array(true)
2614 validate_array('some_string')
2615 $undefined = `undef`
2616 validate_array($undefined)
2617 ```
2618
2619 *Type*: statement.
2620
2621 #### `validate_augeas`
2622
2623 Validates a string using an Augeas lens.
2624
2625 Arguments:
2626
2627 * The string to test, as the first argument.
2628 * The name of the Augeas lens to use, as the second argument.
2629 * Optionally, a list of paths which should **not** be found in the file, as a third argument.
2630 * Optionally, an error message to raise and show to the user, as a fourth argument.
2631
2632 If Augeas fails to parse the string with the lens, the compilation terminates with a parse error.
2633
2634 The `$file` variable points to the location of the temporary file being tested in the Augeas tree.
2635
2636 For example, to make sure your $passwdcontent never contains user `foo`, include the third argument:
2637
2638 ```puppet
2639 validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
2640 ```
2641
2642 To raise and display an error message, include the fourth argument:
2643
2644 ```puppet
2645 validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas')
2646 ```
2647
2648 *Type*: statement.
2649
2650 #### `validate_bool`
2651
2652 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
2653
2654 Validates that all passed values are either `true` or `false`.
2655 Terminates catalog compilation if any value fails this check.
2656
2657 The following values pass:
2658
2659 ```puppet
2660 $iamtrue = true
2661 validate_bool(true)
2662 validate_bool(true, true, false, $iamtrue)
2663 ```
2664
2665 The following values fail, causing compilation to terminate:
2666
2667 ```puppet
2668 $some_array = [ true ]
2669 validate_bool("false")
2670 validate_bool("true")
2671 validate_bool($some_array)
2672 ```
2673
2674 *Type*: statement.
2675
2676 #### `validate_cmd`
2677
2678 Validates a string with an external command.
2679
2680 Arguments:
2681 * The string to test, as the first argument.
2682 * The path to a test command, as the second argument. This argument takes a % as a placeholder for the file path (if no % placeholder is given, defaults to the end of the command). If the command is launched against a tempfile containing the passed string, or returns a non-null value, compilation will terminate with a parse error.
2683 * Optionally, an error message to raise and show to the user, as a third argument.
2684
2685 ```puppet
2686 # Defaults to end of path
2687 validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
2688 ```
2689
2690 ```puppet
2691 # % as file location
2692 validate_cmd($haproxycontent, '/usr/sbin/haproxy -f % -c', 'Haproxy failed to validate config content')
2693 ```
2694
2695 *Type*: statement.
2696
2697 #### `validate_domain_name`
2698
2699 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
2700
2701 Validate that all values passed are syntactically correct domain names. Aborts catalog compilation if any value fails this check.
2702
2703 The following values pass:
2704
2705 ~~~
2706 $my_domain_name = 'server.domain.tld'
2707 validate_domain_name($my_domain_name)
2708 validate_domain_name('domain.tld', 'puppet.com', $my_domain_name)
2709 ~~~
2710
2711 The following values fail, causing compilation to abort:
2712
2713 ~~~
2714 validate_domain_name(1)
2715 validate_domain_name(true)
2716 validate_domain_name('invalid domain')
2717 validate_domain_name('-foo.example.com')
2718 validate_domain_name('www.example.2com')
2719 ~~~
2720
2721 *Type*: statement.
2722
2723 #### `validate_email_address`
2724
2725 Validate that all values passed are valid email addresses. Fail compilation if any value fails this check.
2726
2727 The following values will pass:
2728
2729 ~~~
2730 $my_email = "waldo@gmail.com"
2731 validate_email_address($my_email)
2732 validate_email_address("bob@gmail.com", "alice@gmail.com", $my_email)
2733 ~~~
2734
2735 The following values will fail, causing compilation to abort:
2736
2737 ~~~
2738 $some_array = [ 'bad_email@/d/efdf.com' ]
2739 validate_email_address($some_array)
2740 ~~~
2741
2742 *Type*: statement.
2743
2744 #### `validate_hash`
2745
2746 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
2747
2748 Validates that all passed values are hash data structures. Terminates catalog compilation if any value fails this check.
2749
2750 The following values will pass:
2751
2752 ```puppet
2753 $my_hash = { 'one' => 'two' }
2754 validate_hash($my_hash)
2755 ```
2756
2757 The following values will fail, causing compilation to terminate:
2758
2759 ```puppet
2760 validate_hash(true)
2761 validate_hash('some_string')
2762 $undefined = `undef`
2763 validate_hash($undefined)
2764 ```
2765
2766 *Type*: statement.
2767
2768 #### `validate_integer`
2769
2770 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
2771
2772 Validates an integer or an array of integers. Terminates catalog compilation if any of the checks fail.
2773
2774 Arguments:
2775
2776 * An integer or an array of integers, as the first argument.
2777 * Optionally, a maximum, as the second argument. (All elements of) the first argument must be equal to or less than this maximum.
2778 * Optionally, a minimum, as the third argument. (All elements of) the first argument must be equal to or greater than than this maximum.
2779
2780 This function fails if the first argument is not an integer or array of integers, or if the second or third arguments are not convertable to an integer. However, if (and only if) a minimum is given, the second argument may be an empty string or `undef`, which serves as a placeholder to ensure the minimum check.
2781
2782 The following values pass:
2783
2784 ```puppet
2785 validate_integer(1)
2786 validate_integer(1, 2)
2787 validate_integer(1, 1)
2788 validate_integer(1, 2, 0)
2789 validate_integer(2, 2, 2)
2790 validate_integer(2, '', 0)
2791 validate_integer(2, `undef`, 0)
2792 $foo = `undef`
2793 validate_integer(2, $foo, 0)
2794 validate_integer([1,2,3,4,5], 6)
2795 validate_integer([1,2,3,4,5], 6, 0)
2796 ```
2797
2798 * Plus all of the above, but any combination of values passed as strings ('1' or "1").
2799 * Plus all of the above, but with (correct) combinations of negative integer values.
2800
2801 The following values fail, causing compilation to terminate:
2802
2803 ```puppet
2804 validate_integer(true)
2805 validate_integer(false)
2806 validate_integer(7.0)
2807 validate_integer({ 1 => 2 })
2808 $foo = `undef`
2809 validate_integer($foo)
2810 validate_integer($foobaridontexist)
2811
2812 validate_integer(1, 0)
2813 validate_integer(1, true)
2814 validate_integer(1, '')
2815 validate_integer(1, `undef`)
2816 validate_integer(1, , 0)
2817 validate_integer(1, 2, 3)
2818 validate_integer(1, 3, 2)
2819 validate_integer(1, 3, true)
2820 ```
2821
2822 * Plus all of the above, but any combination of values passed as strings (`false` or "false").
2823 * Plus all of the above, but with incorrect combinations of negative integer values.
2824 * Plus all of the above, but with non-integer items in arrays or maximum / minimum argument.
2825
2826 *Type*: statement.
2827
2828 #### `validate_ip_address`
2829
2830 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
2831
2832 Validates that the argument is an IP address, regardless of whether it is an IPv4 or an IPv6 address. It also validates IP address with netmask.
2833
2834 Arguments: A string specifying an IP address.
2835
2836 The following values will pass:
2837
2838 ```puppet
2839 validate_ip_address('0.0.0.0')
2840 validate_ip_address('8.8.8.8')
2841 validate_ip_address('127.0.0.1')
2842 validate_ip_address('194.232.104.150')
2843 validate_ip_address('3ffe:0505:0002::')
2844 validate_ip_address('::1/64')
2845 validate_ip_address('fe80::a00:27ff:fe94:44d6/64')
2846 validate_ip_address('8.8.8.8/32')
2847 ```
2848
2849 The following values will fail, causing compilation to terminate:
2850
2851 ```puppet
2852 validate_ip_address(1)
2853 validate_ip_address(true)
2854 validate_ip_address(0.0.0.256)
2855 validate_ip_address('::1', {})
2856 validate_ip_address('0.0.0.0.0')
2857 validate_ip_address('3.3.3')
2858 validate_ip_address('23.43.9.22/64')
2859 validate_ip_address('260.2.32.43')
2860 ```
2861
2862
2863 #### `validate_legacy`
2864
2865 Validates a value against both a specified type and a deprecated validation function. Silently passes if both pass, errors if only one validation passes, and fails if both validations return false.
2866
2867 Arguments:
2868
2869 * The type to check the value against,
2870 * The full name of the previous validation function,
2871 * The value to be checked,
2872 * An unspecified number of arguments needed for the previous validation function.
2873
2874 Example:
2875
2876 ```puppet
2877 validate_legacy('Optional[String]', 'validate_re', 'Value to be validated', ["."])
2878 ```
2879
2880 This function supports updating modules from Puppet 3-style argument validation (using the stdlib `validate_*` functions) to Puppet 4 data types, without breaking functionality for those depending on Puppet 3-style validation.
2881
2882 > Note: This function is compatible only with Puppet 4.4.0 (PE 2016.1) and later.
2883
2884 ##### For module users
2885
2886 If you are running Puppet 4, the `validate_legacy` function can help you find and resolve deprecated Puppet 3 `validate_*` functions. These functions are deprecated as of stdlib version 4.13 and will be removed in a future version of stdlib.
2887
2888 Puppet 4 allows improved defined type checking using [data types](https://puppet.com/docs/puppet/latest/lang_data.html). Data types avoid some of the problems with Puppet 3's `validate_*` functions, which were sometimes inconsistent. For example, [validate_numeric](#validate_numeric) unintentionally allowed not only numbers, but also arrays of numbers or strings that looked like numbers.
2889
2890 If you run Puppet 4 and use modules with deprecated `validate_*` functions, you might encounter deprecation messages. The `validate_legacy` function makes these differences visible and makes it easier to move to the clearer Puppet 4 syntax.
2891
2892 The deprecation messages you get can vary, depending on the modules and data that you use. These deprecation messages appear by default only in Puppet 4:
2893
2894 * `Notice: Accepting previously invalid value for target type '<type>'`: This message is informational only. You're using values that are allowed by the new type, but would have been invalid by the old validation function.
2895 * `Warning: This method is deprecated, please use the stdlib validate_legacy function`: The module has not yet upgraded to `validate_legacy`. Use the [deprecation](#deprecation) options to silence warnings for now, or submit a fix with the module's developer. See the information [for module developers](#for-module-developers) below for how to fix the issue.
2896 * `Warning: validate_legacy(<function>) expected <type> value, got <actual type>_`: Your code passes a value that was accepted by the Puppet 3-style validation, but will not be accepted by the next version of the module. Most often, you can fix this by removing quotes from numbers or booleans.
2897 * `Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, validate_legacy(<function>) expected <type> value, got <actual type>`: Your code passes a value that is not acceptable to either the new or the old style validation.
2898
2899 ##### For module developers
2900
2901 The `validate_legacy` function helps you move from Puppet 3 style validation to Puppet 4 validation without breaking functionality your module's users depend on.
2902
2903 Moving to Puppet 4 type validation allows much better defined type checking using [data types](https://puppet.com/docs/puppet/latest/lang_data.html). Many of Puppet 3's `validate_*` functions have surprising holes in their validation. For example, [validate_numeric](#validate_numeric) allows not only numbers, but also arrays of numbers or strings that look like numbers, without giving you any control over the specifics.
2904
2905 For each parameter of your classes and defined types, choose a new Puppet 4 data type to use. In most cases, the new data type allows a different set of values than the original `validate_*` function. The situation then looks like this:
2906
2907 |              | `validate_` pass | `validate_` fail |
2908 | ------------ | ---------------- | ---------------- |
2909 | matches type | pass             | pass, notice     |
2910 | fails type   | pass, deprecated | fail             |
2911
2912 The code after the validation still has to handle all possible values for now, but users of your code can change their manifests to pass only values that match the new type.
2913
2914 For each `validate_*` function in stdlib, there is a matching `Stdlib::Compat::*` type that allows the appropriate set of values. See the documentation in the `types/` directory in the stdlib source code for caveats.
2915
2916 For example, given a class that should accept only numbers, like this:
2917
2918 ```puppet
2919 class example($value) {
2920   validate_numeric($value)
2921 ```
2922
2923 the resulting validation code looks like this:
2924
2925 ```puppet
2926 class example(
2927   Variant[Stdlib::Compat::Numeric, Numeric] $value
2928 ) {
2929   validate_legacy(Numeric, 'validate_numeric', $value)
2930 ```
2931
2932 Here, the type of `$value` is defined as `Variant[Stdlib::Compat::Numeric, Numeric]`, which allows any `Numeric` (the new type), as well as all values previously accepted by `validate_numeric` (through `Stdlib::Compat::Numeric`).
2933
2934 The call to `validate_legacy` takes care of triggering the correct log or fail message for you. It requires the new type, the previous validation function name, and all arguments to that function.
2935
2936 If your module still supported Puppet 3, this is a breaking change. Update your `metadata.json` requirements section to indicate that your module no longer supports Puppet 3, and bump the major version of your module. With this change, all existing tests for your module should still pass. Create additional tests for the new possible values.
2937
2938 As a breaking change, this is also a good time to call [`deprecation`](#deprecation) for any parameters you want to get rid of, or to add additional constraints on your parameters.
2939
2940 After releasing this version, you can release another breaking change release where you remove all compat types and all calls to `validate_legacy`. At that time, you can also go through your code and remove any leftovers dealing with the previously possible values.
2941
2942 Always note such changes in your CHANGELOG and README.
2943
2944 #### `validate_numeric`
2945
2946 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
2947
2948 Validates a numeric value, or an array or string of numeric values. Terminates catalog compilation if any of the checks fail.
2949
2950 Arguments:
2951
2952 * A numeric value, or an array or string of numeric values.
2953 * Optionally, a maximum value. (All elements of) the first argument has to be less or equal to this max.
2954 * Optionally, a minimum value. (All elements of) the first argument has to be greater or equal to this min.
2955
2956 This function fails if the first argument is not a numeric (Integer or Float) or an array or string of numerics, or if the second and third arguments are not convertable to a numeric. If, and only if, a minimum is given, the second argument can be an empty string or `undef`, which serves as a placeholder to ensure the minimum check.
2957
2958 For passing and failing usage, see [`validate_integer`](#validate-integer). The same values pass and fail, except that `validate_numeric` also allows floating point values.
2959
2960 *Type*: statement.
2961
2962 #### `validate_re`
2963
2964 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
2965
2966 Performs simple validation of a string against one or more regular expressions.
2967
2968 Arguments:
2969
2970 * The string to test, as the first argument. If this argument is not a string, compilation terminates. Use quotes to force stringification.
2971 * A stringified regular expression (without the // delimiters) or an array of regular expressions, as the second argument.
2972 * Optionally, the error message raised and shown to the user, as a third argument.
2973
2974 If none of the regular expressions in the second argument match the string passed in the first argument, compilation terminates with a parse error.
2975
2976 The following strings validate against the regular expressions:
2977
2978 ```puppet
2979 validate_re('one', '^one$')
2980 validate_re('one', [ '^one', '^two' ])
2981 ```
2982
2983 The following string fails to validate, causing compilation to terminate:
2984
2985 ```puppet
2986 validate_re('one', [ '^two', '^three' ])
2987 ```
2988
2989 To set the error message:
2990
2991 ```puppet
2992 validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
2993 ```
2994
2995 To force stringification, use quotes:
2996
2997   ```
2998   validate_re("${::operatingsystemmajrelease}", '^[57]$')
2999   ```
3000
3001 *Type*: statement.
3002
3003 #### `validate_slength`
3004
3005 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
3006
3007 Validates that a string (or an array of strings) is less than or equal to a specified length
3008
3009 Arguments:
3010
3011 * A string or an array of strings, as a first argument.
3012 * A numeric value for maximum length, as a second argument.
3013 * Optionally, a numeric value for minimum length, as a third argument.
3014
3015   The following values pass:
3016
3017 ```puppet
3018 validate_slength("discombobulate",17)
3019 validate_slength(["discombobulate","moo"],17)
3020 validate_slength(["discombobulate","moo"],17,3)
3021 ```
3022
3023 The following values fail:
3024
3025 ```puppet
3026 validate_slength("discombobulate",1)
3027 validate_slength(["discombobulate","thermometer"],5)
3028 validate_slength(["discombobulate","moo"],17,10)
3029 ```
3030
3031 *Type*: statement.
3032
3033 #### `validate_string`
3034
3035 **Deprecated:** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).
3036
3037 Validates that all passed values are string data structures. Aborts catalog compilation if any value fails this check.
3038
3039 The following values pass:
3040
3041 ```puppet
3042 $my_string = "one two"
3043 validate_string($my_string, 'three')
3044 ```
3045
3046 The following values fail, causing compilation to terminate:
3047
3048 ```puppet
3049 validate_string(true)
3050 validate_string([ 'some', 'array' ])
3051 ```
3052
3053 > *Note:* validate_string(`undef`) will not fail in this version of the functions API.
3054
3055 Instead, use:
3056
3057   ```
3058   if $var == `undef` {
3059     fail('...')
3060   }
3061   ```
3062
3063 *Type*: statement.
3064
3065 #### `validate_x509_rsa_key_pair`
3066
3067 Validates a PEM-formatted X.509 certificate and private key using OpenSSL.
3068 Verifies that the certificate's signature was created from the supplied key.
3069
3070 Fails catalog compilation if any value fails this check.
3071
3072 Arguments:
3073
3074 * An X.509 certificate as the first argument.
3075 * An RSA private key, as the second argument.
3076
3077 ```puppet
3078 validate_x509_rsa_key_pair($cert, $key)
3079 ```
3080
3081 *Type*: statement.
3082
3083 #### `values`
3084
3085 **Deprecated:** This function has been replaced with a built-in [`values`](https://puppet.com/docs/puppet/latest/function.html#values) function as of Puppet 5.5.0.
3086
3087 Returns the values of a given hash.
3088
3089 For example, given `$hash = {'a'=1, 'b'=2, 'c'=3} values($hash)` returns [1,2,3].
3090
3091 *Type*: rvalue.
3092
3093 #### `values_at`
3094
3095 Finds values inside an array based on location.
3096
3097 Arguments:
3098
3099 * The array you want to analyze, as the first argument.
3100 * Any combination of the following values, as the second argument:
3101   * A single numeric index
3102   * A range in the form of 'start-stop' (eg. 4-9)
3103   * An array combining the above
3104
3105 For example:
3106
3107 * `values_at(['a','b','c'], 2)` returns ['c'].
3108 * `values_at(['a','b','c'], ["0-1"])` returns ['a','b'].
3109 * `values_at(['a','b','c','d','e'], [0, "2-3"])` returns ['a','c','d'].
3110
3111 Since Puppet 4.0.0, you can slice an array with index and count directly in the language.
3112 A negative value is taken to be "from the end" of the array, for example:
3113
3114 ```puppet
3115 ['a', 'b', 'c', 'd'][1, 2]   # results in ['b', 'c']
3116 ['a', 'b', 'c', 'd'][2, -1]  # results in ['c', 'd']
3117 ['a', 'b', 'c', 'd'][1, -2]  # results in ['b', 'c']
3118 ```
3119
3120 *Type*: rvalue.
3121
3122 #### `zip`
3123
3124 Takes one element from first array given and merges corresponding elements from second array given. This generates a sequence of n-element arrays, where *n* is one more than the count of arguments. For example, `zip(['1','2','3'],['4','5','6'])` results in ["1", "4"], ["2", "5"], ["3", "6"]. *Type*: rvalue.
3125
3126 <a id="limitations"></a>
3127 ## Limitations
3128
3129 As of Puppet Enterprise 3.7, the stdlib module is no longer included in PE. PE users should install the most recent release of stdlib for compatibility with Puppet modules.
3130
3131 For an extensive list of supported operating systems, see [metadata.json](https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/metadata.json)
3132
3133 <a id="development"></a>
3134 ## Development
3135
3136 Puppet modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. For more information, see our [module contribution guide](https://docs.puppet.com/forge/contributing.html).
3137
3138 To report or research a bug with any part of this module, please go to
3139 [http://tickets.puppetlabs.com/browse/MODULES](http://tickets.puppetlabs.com/browse/MODULES).
3140
3141 <a id="contributors"></a>
3142 ## Contributors
3143
3144 The list of contributors can be found at: [https://github.com/puppetlabs/puppetlabs-stdlib/graphs/contributors](https://github.com/puppetlabs/puppetlabs-stdlib/graphs/contributors).