source: src/puppetcode/environments/test/modules/stdlib/README.markdown@ 1533ca1

debian/bullseye debian/jessie
Last change on this file since 1533ca1 was 1c22429, checked in by Joachim Langenbach <joachim.langenbach@…>, 10 years ago
  • gnuboat_epd adds the apt repository from gnuboat to install epd-fuse package
  • Property mode set to 100644
File size: 47.4 KB
RevLine 
[1c22429]1#stdlib
2
3####Table of Contents
4
51. [Overview](#overview)
62. [Module Description - What the module does and why it is useful](#module-description)
73. [Setup - The basics of getting started with stdlib](#setup)
84. [Usage - Configuration options and additional functionality](#usage)
95. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
105. [Limitations - OS compatibility, etc.](#limitations)
116. [Development - Guide for contributing to the module](#development)
12
13##Overview
14
15Adds a standard library of resources for Puppet modules.
16
17##Module Description
18
19This module provides a standard library of resources for the development of Puppet modules. Puppet modules make heavy use of this standard library. The stdlib module adds the following resources to Puppet:
20
21 * Stages
22 * Facts
23 * Functions
24 * Defined resource types
25 * Types
26 * Providers
27
28> *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.
29
30##Setup
31
32Installing the stdlib module adds the functions, facts, and resources of this standard library to Puppet.
33
34##Usage
35
36After you've installed stdlib, all of its functions, facts, and resources are available for module use or development.
37
38If you want to use a standardized set of run stages for Puppet, `include stdlib` in your manifest.
39
40* `stdlib`: 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`.
41
42 When declared, stdlib declares all other classes in the module. The only other class currently included in the module is `stdlib::stages`.
43
44The `stdlib::stages` class declares various run stages for deploying infrastructure, language runtimes, and application layers. The high level stages are (in order):
45
46 * setup
47 * main
48 * runtime
49 * setup_infra
50 * deploy_infra
51 * setup_app
52 * deploy_app
53 * deploy
54
55 Sample usage:
56
57 ~~~
58 node default {
59 include stdlib
60 class { java: stage => 'runtime' }
61 }
62 ~~~
63
64## Reference
65
66### Classes
67
68#### Public Classes
69
70 The stdlib class has no parameters.
71
72#### Private Classes
73
74* `stdlib::stages`: Manages a standard set of run stages for Puppet. It is managed by the stdlib class and should not be declared independently.
75
76### Types
77
78#### `file_line`
79
80Ensures 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.
81
82Example:
83
84 file_line { 'sudo_rule':
85 path => '/etc/sudoers',
86 line => '%sudo ALL=(ALL) ALL',
87 }
88
89 file_line { 'sudo_rule_nopw':
90 path => '/etc/sudoers',
91 line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
92 }
93
94In this example, Puppet ensures that both of the specified lines are contained in the file `/etc/sudoers`.
95
96Match Example:
97
98 file_line { 'bashrc_proxy':
99 ensure => present,
100 path => '/etc/bashrc',
101 line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
102 match => '^export\ HTTP_PROXY\=',
103 }
104
105In this code example, `match` looks for a line beginning with export followed by HTTP_PROXY and replaces it with the value in line.
106
107Match Example With `ensure => absent`:
108
109 file_line { 'bashrc_proxy':
110 ensure => absent,
111 path => '/etc/bashrc',
112 line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
113 match => '^export\ HTTP_PROXY\=',
114 match_for_absence => true,
115 }
116
117In this code example, `match` looks for a line beginning with export
118followed by HTTP_PROXY and delete it. If multiple lines match, an
119error will be raised unless the `multiple => true` parameter is set.
120
121**Autorequires:** If Puppet is managing the file that contains the line being managed, the `file_line` resource autorequires that file.
122
123##### Parameters
124
125All parameters are optional, unless otherwise noted.
126
127* `after`: Specifies the line after which Puppet adds any new lines. (Existing lines are added in place.) Valid options: String. Default: Undefined.
128* `ensure`: Ensures whether the resource is present. Valid options: 'present', 'absent'. Default: 'present'.
129* `line`: **Required.** Sets the line to be added to the file located by the `path` parameter. Valid options: String. Default: Undefined.
130* `match`: Specifies a regular expression to run against existing lines in the file; if a match is found, it is replaced rather than adding a new line. A regex comparison is performed against the line value, and if it does not match, an exception is raised. Valid options: String containing a regex. Default: Undefined.
131* `match_for_absence`: An optional value to determine if match should be applied when `ensure => absent`. If set to true and match is set, the line that matches match will be deleted. If set to false (the default), match is ignored when `ensure => absent` and the value of `line` is used instead. Default: false.
132* `multiple`: Determines if `match` and/or `after` can change multiple lines. If set to false, an exception will be raised if more than one line matches. Valid options: 'true', 'false'. Default: Undefined.
133* `name`: Sets the name to use as the identity of the resource. This is necessary if you want the resource namevar to differ from the supplied `title` of the resource. Valid options: String. Default: Undefined.
134* `path`: **Required.** Defines the file in which Puppet will ensure the line specified by `line`. Must be an absolute path to the file.
135* `replace`: Defines whether the resource will overwrite an existing line that matches the `match` parameter. If set to false and a line is found matching the `match` param, the line will not be placed in the file. Valid options: true, false, yes, no. Default: true
136
137### Functions
138
139#### `abs`
140
141Returns the absolute value of a number; for example, '-34.56' becomes '34.56'. Takes a single integer and float value as an argument. *Type*: rvalue.
142
143#### `any2array`
144
145Converts any object to an array containing that object. Empty argument lists are converted to an empty array. Arrays are left untouched. Hashes are converted to arrays of alternating keys and values. *Type*: rvalue.
146
147#### `base64`
148
149Converts 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')
150
151For backward compatibility, `method` will be set as `default` if not specified.
152
153*Examples:*
154~~~
155base64('encode', 'hello')
156base64('encode', 'hello', 'default')
157# return: "aGVsbG8=\n"
158
159base64('encode', 'hello', 'strict')
160# return: "aGVsbG8="
161
162base64('decode', 'aGVsbG8=')
163base64('decode', 'aGVsbG8=\n')
164base64('decode', 'aGVsbG8=', 'default')
165base64('decode', 'aGVsbG8=\n', 'default')
166base64('decode', 'aGVsbG8=', 'strict')
167# return: "hello"
168
169base64('encode', 'https://puppetlabs.com', 'urlsafe')
170# return: "aHR0cHM6Ly9wdXBwZXRsYWJzLmNvbQ=="
171
172base64('decode', 'aHR0cHM6Ly9wdXBwZXRsYWJzLmNvbQ==', 'urlsafe')
173# return: "https://puppetlabs.com"
174~~~
175
176*Type*: rvalue.
177
178#### `basename`
179
180Returns the `basename` of a path (optionally stripping an extension). For example:
181 * ('/path/to/a/file.ext') returns 'file.ext'
182 * ('relative/path/file.ext') returns 'file.ext'
183 * ('/path/to/a/file.ext', '.ext') returns 'file'
184
185*Type*: rvalue.
186
187#### `bool2num`
188
189Converts a boolean to a number. Converts values:
190 * 'false', 'f', '0', 'n', and 'no' to 0.
191 * 'true', 't', '1', 'y', and 'yes' to 1.
192 Requires a single boolean or string as an input. *Type*: rvalue.
193
194#### `bool2str`
195
196Converts 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'.
197
198*Examples:*
199~~~
200bool2str(true) => 'true'
201bool2str(true, 'yes', 'no') => 'yes'
202bool2str(false, 't', 'f') => 'f'
203~~~
204
205Requires a single boolean as input. *Type*: rvalue.
206
207#### `capitalize`
208
209Capitalizes the first character of a string or array of strings and lowercases the remaining characters of each string. Requires either a single string or an array as an input. *Type*: rvalue.
210
211#### `ceiling`
212
213Returns the smallest integer greater than or equal to the argument. Takes a single numeric value as an argument. *Type*: rvalue.
214
215#### `chomp`
216
217Removes the record separator from the end of a string or an array of strings; for example, 'hello\n' becomes 'hello'. Requires a single string or array as an input. *Type*: rvalue.
218
219#### `chop`
220
221Returns 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. If you want to merely remove record separators, then you should use the `chomp` function. Requires a string or an array of strings as input. *Type*: rvalue.
222
223#### `clamp`
224
225Keeps value within the range [Min, X, Max] by sort based on integer value (order of params doesn't matter). Takes strings, arrays or numerics. Strings are converted and compared numerically. Arrays of values are flattened into a list for further handling. For example:
226 * `clamp('24', [575, 187])` returns 187.
227 * `clamp(16, 88, 661)` returns 88.
228 * `clamp([4, 3, '99'])` returns 4.
229 *Type*: rvalue.
230
231#### `concat`
232
233Appends the contents of multiple arrays onto the first array given. For example:
234 * `concat(['1','2','3'],'4')` returns ['1','2','3','4'].
235 * `concat(['1','2','3'],'4',['5','6','7'])` returns ['1','2','3','4','5','6','7'].
236 *Type*: rvalue.
237
238#### `convert_base`
239
240Converts a given integer or base 10 string representing an integer to a specified base, as a string. For example:
241 * `convert_base(5, 2)` results in: '101'
242 * `convert_base('254', '16')` results in: 'fe'
243
244#### `count`
245
246If called with only an array, it counts the number of elements that are **not** nil/undef. If called with a second argument, counts the number of elements in an array that matches the second argument. *Type*: rvalue.
247
248#### `defined_with_params`
249
250Takes 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.
251
252 ~~~
253 user { 'dan':
254 ensure => present,
255 }
256
257 if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
258 user { 'dan': ensure => present, }
259 }
260 ~~~
261
262*Type*: rvalue.
263
264#### `delete`
265
266Deletes all instances of a given element from an array, substring from a string, or key from a hash. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. `delete({'a' => 1,'b' => 2,'c' => 3},['b','c'])` returns {'a'=> 1}. *Type*: rvalue.
267
268#### `delete_at`
269
270Deletes a determined indexed value from an array. For example, `delete_at(['a','b','c'], 1)` returns ['a','c']. *Type*: rvalue.
271
272#### `delete_values`
273
274Deletes all instances of a given value from a hash. For example, `delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')` returns {'a'=>'A','c'=>'C','B'=>'D'} *Type*: rvalue.
275
276#### `delete_undef_values`
277
278Deletes all instances of the undef value from an array or hash. For example, `$hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false})` returns {a => 'A', b => '', d => false}. *Type*: rvalue.
279
280#### `difference`
281
282Returns 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. For example, `difference(["a","b","c"],["b","c","d"])` returns ["a"]. *Type*: rvalue.
283
284#### `dig`
285
286*Type*: rvalue.
287
288Retrieves 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.
289
290In 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.
291
292~~~ruby
293$data = {
294 'a' => {
295 'b' => [
296 'b1',
297 'b2',
298 'b3',
299 ]
300 }
301}
302
303$value = dig($data, ['a', 'b', 2])
304# $value = 'b3'
305
306# with all possible options
307$value = dig($data, ['a', 'b', 2], 'not_found')
308# $value = 'b3'
309
310# using the default value
311$value = dig($data, ['a', 'b', 'c', 'd'], 'not_found')
312# $value = 'not_found'
313~~~
314
3151. **$data** The data structure we are working with.
3162. **['a', 'b', 2]** The path array.
3173. **'not_found'** The default value. It will be returned if nothing is found.
318 (optional, defaults to *undef*)
319
320#### `dirname`
321
322Returns the `dirname` of a path. For example, `dirname('/path/to/a/file.ext')` returns '/path/to/a'. *Type*: rvalue.
323
324#### `dos2unix`
325
326Returns the Unix version of the given string. Very useful when using a File resource with a cross-platform template. *Type*: rvalue.
327
328~~~
329file{$config_file:
330 ensure => file,
331 content => dos2unix(template('my_module/settings.conf.erb')),
332}
333~~~
334
335See also [unix2dos](#unix2dos).
336
337#### `downcase`
338
339Converts the case of a string or of all strings in an array to lowercase. *Type*: rvalue.
340
341#### `empty`
342
343Returns 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. *Type*: rvalue.
344
345#### `enclose_ipv6`
346
347Takes an array of ip addresses and encloses the ipv6 addresses with square brackets. *Type*: rvalue.
348
349#### `ensure_packages`
350
351Takes a list of packages array/hash and only installs them if they don't already exist. It optionally takes a hash as a second parameter to be passed as the third argument to the `ensure_resource()` or `ensure_resources()` function. *Type*: statement.
352
353For Array:
354
355 ensure_packages(['ksh','openssl'], {'ensure' => 'present'})
356
357For Hash:
358
359 ensure_packages({'ksh' => { enure => '20120801-1' } , 'mypackage' => { source => '/tmp/myrpm-1.0.0.x86_64.rpm', provider => "rpm" }}, {'ensure' => 'present'})
360
361#### `ensure_resource`
362
363Takes a resource type, title, and a hash of attributes that describe the resource(s).
364
365~~~
366user { 'dan':
367 ensure => present,
368}
369~~~
370
371This example only creates the resource if it does not already exist:
372
373 `ensure_resource('user', 'dan', {'ensure' => 'present' })`
374
375If 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.
376
377An 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.
378
379 `ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})`
380
381*Type*: statement.
382
383#### `ensure_resources`
384
385Takes a resource type, title (only hash), and a hash of attributes that describe the resource(s).
386
387~~~
388user { 'dan':
389 gid => 'mygroup',
390 ensure => present,
391}
392
393ensure_resources($user)
394~~~
395
396An hash of resources should be passed in and each will be created with the type and parameters specified if it doesn't already exist:
397
398 ensure_resources('user', {'dan' => { gid => 'mygroup', uid => '600' } , 'alex' => { gid => 'mygroup' }}, {'ensure' => 'present'})
399
400From Hiera Backend:
401
402~~~
403userlist:
404dan:
405 gid: 'mygroup'
406uid: '600'
407alex:
408gid: 'mygroup'
409
410ensure_resources('user', hiera_hash('userlist'), {'ensure' => 'present'})
411~~~
412
413### `flatten`
414
415Flattens deeply nested arrays and returns a single flat array as a result. For example, `flatten(['a', ['b', ['c']]])` returns ['a','b','c']. *Type*: rvalue.
416
417#### `floor`
418
419Takes a single numeric value as an argument, and returns the largest integer less than or equal to the argument. *Type*: rvalue.
420
421#### `fqdn_rand_string`
422
423Generates a random alphanumeric string using an optionally-specified character set (default is alphanumeric), combining the `$fqdn` fact and an optional seed for repeatable randomness.
424
425*Usage:*
426~~~
427fqdn_rand_string(LENGTH, [CHARSET], [SEED])
428~~~
429*Examples:*
430~~~
431fqdn_rand_string(10)
432fqdn_rand_string(10, 'ABCDEF!@#$%^')
433fqdn_rand_string(10, '', 'custom seed')
434~~~
435
436*Type*: rvalue.
437
438#### `fqdn_rotate`
439
440Rotates an array or string a random number of times, combining the `$fqdn` fact and an optional seed for repeatable randomness.
441
442*Usage:*
443
444~~~
445fqdn_rotate(VALUE, [SEED])
446~~~
447
448*Examples:*
449
450~~~
451fqdn_rotate(['a', 'b', 'c', 'd'])
452fqdn_rotate('abcd')
453fqdn_rotate([1, 2, 3], 'custom seed')
454~~~
455
456*Type*: rvalue.
457
458#### `get_module_path`
459
460Returns the absolute path of the specified module for the current environment.
461
462 `$module_path = get_module_path('stdlib')`
463
464*Type*: rvalue.
465
466#### `getparam`
467
468Takes a resource reference and the name of the parameter, and returns the value of the resource's parameter.
469
470For example, the following returns 'param_value':
471
472 ~~~
473 define example_resource($param) {
474 }
475
476 example_resource { "example_resource_instance":
477 param => "param_value"
478 }
479
480 getparam(Example_resource["example_resource_instance"], "param")
481 ~~~
482
483*Type*: rvalue.
484
485#### `getvar`
486
487Looks up a variable in a remote namespace.
488
489For example:
490
491 ~~~
492 $foo = getvar('site::data::foo')
493 # Equivalent to $foo = $site::data::foo
494 ~~~
495
496This is useful if the namespace itself is stored in a string:
497
498 ~~~
499 $datalocation = 'site::data'
500 $bar = getvar("${datalocation}::bar")
501 # Equivalent to $bar = $site::data::bar
502 ~~~
503
504*Type*: rvalue.
505
506#### `grep`
507
508Searches through an array and returns any elements that match the provided regular expression. For example, `grep(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['aaa','aaaddd']. *Type*: rvalue.
509
510#### `has_interface_with`
511
512Returns a boolean based on kind and value:
513 * macaddress
514 * netmask
515 * ipaddress
516 * network
517
518*Examples:*
519
520 ~~~
521 has_interface_with("macaddress", "x:x:x:x:x:x")
522 has_interface_with("ipaddress", "127.0.0.1") => true
523 ~~~
524
525If no kind is given, then the presence of the interface is checked:
526
527 ~~~
528 has_interface_with("lo") => true
529 ~~~
530
531*Type*: rvalue.
532
533#### `has_ip_address`
534
535Returns '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. *Type*: rvalue.
536
537#### `has_ip_network`
538
539Returns '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. *Type*: rvalue.
540
541#### `has_key`
542
543Determines if a hash has a certain key value.
544
545*Example*:
546
547 ~~~
548 $my_hash = {'key_one' => 'value_one'}
549 if has_key($my_hash, 'key_two') {
550 notice('we will not reach here')
551 }
552 if has_key($my_hash, 'key_one') {
553 notice('this will be printed')
554 }
555 ~~~
556
557*Type*: rvalue.
558
559#### `hash`
560
561Converts an array into a hash. For example, `hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}. *Type*: rvalue.
562
563#### `intersection`
564
565Returns an array an intersection of two. For example, `intersection(["a","b","c"],["b","c","d"])` returns ["b","c"]. *Type*: rvalue.
566
567#### `is_a`
568
569Boolean 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.
570
571 ~~~
572 foo = 3
573 $bar = [1,2,3]
574 $baz = 'A string!'
575
576 if $foo.is_a(Integer) {
577 notify { 'foo!': }
578 }
579 if $bar.is_a(Array) {
580 notify { 'bar!': }
581 }
582 if $baz.is_a(String) {
583 notify { 'baz!': }
584 }
585 ~~~
586
587See the [the Puppet type system](https://docs.puppetlabs.com/references/latest/type.html#about-resource-types) for more information about types.
588See the [`assert_type()`](https://docs.puppetlabs.com/references/latest/function.html#asserttype) function for flexible ways to assert the type of a value.
589
590#### `is_absolute_path`
591
592Returns 'true' if the given path is absolute. *Type*: rvalue.
593
594#### `is_array`
595
596Returns 'true' if the variable passed to this function is an array. *Type*: rvalue.
597
598#### `is_bool`
599
600Returns 'true' if the variable passed to this function is a boolean. *Type*: rvalue.
601
602#### `is_domain_name`
603
604Returns 'true' if the string passed to this function is a syntactically correct domain name. *Type*: rvalue.
605
606#### `is_float`
607
608Returns 'true' if the variable passed to this function is a float. *Type*: rvalue.
609
610#### `is_function_available`
611
612Accepts 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. *Type*: rvalue.
613
614#### `is_hash`
615
616Returns 'true' if the variable passed to this function is a hash. *Type*: rvalue.
617
618#### `is_integer`
619
620Returns 'true' if the variable returned to this string is an integer. *Type*: rvalue.
621
622#### `is_ip_address`
623
624Returns 'true' if the string passed to this function is a valid IP address. *Type*: rvalue.
625
626#### `is_ipv6_address`
627
628Returns 'true' if the string passed to this function is a valid IPv6 address. *Type*: rvalue.
629
630#### `is_ipv4_address`
631
632Returns 'true' if the string passed to this function is a valid IPv4 address. *Type*: rvalue.
633
634#### `is_mac_address`
635
636Returns 'true' if the string passed to this function is a valid MAC address. *Type*: rvalue.
637
638#### `is_numeric`
639
640Returns 'true' if the variable passed to this function is a number. *Type*: rvalue.
641
642#### `is_string`
643
644Returns 'true' if the variable passed to this function is a string. *Type*: rvalue.
645
646#### `join`
647
648Joins an array into a string using a separator. For example, `join(['a','b','c'], ",")` results in: "a,b,c". *Type*: rvalue.
649
650#### `join_keys_to_values`
651
652Joins each key of a hash to that key's corresponding value with a separator. Keys and values are cast to strings. The return value is an array in which each element is one joined key/value pair. For example, `join_keys_to_values({'a'=>1,'b'=>2}, " is ")` results in ["a is 1","b is 2"]. *Type*: rvalue.
653
654#### `keys`
655
656Returns the keys of a hash as an array. *Type*: rvalue.
657
658#### `loadyaml`
659
660Loads a YAML file containing an array, string, or hash, and returns the data in the corresponding native data type. For example:
661
662 ~~~
663 $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
664 ~~~
665
666*Type*: rvalue.
667
668#### `load_module_metadata`
669
670Loads the metadata.json of a target module. Can be used to determine module version and authorship for dynamic support of modules.
671
672 ~~~
673 $metadata = load_module_metadata('archive')
674 notify { $metadata['author']: }
675 ~~~
676
677If you do not want to fail the catalog compilation when a module's metadata file is absent:
678
679 ~~~
680 $metadata = load_module_metadata('mysql', true)
681 if empty($metadata) {
682 notify { "This module does not have a metadata.json file.": }
683 }
684 ~~~
685
686*Type*: rvalue.
687
688#### `lstrip`
689
690Strips spaces to the left of a string. *Type*: rvalue.
691
692#### `max`
693
694Returns the highest value of all arguments. Requires at least one argument. *Type*: rvalue.
695
696#### `member`
697
698This function determines if a variable is a member of an array. The variable can be either a string, array, or fixnum. 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'. *Note*: This function does not support nested arrays. If the first argument contains nested arrays, it will not recurse through them.
699
700*Type*: rvalue.
701
702#### `merge`
703
704Merges two or more hashes together and returns the resulting hash.
705
706*Example*:
707
708 ~~~
709 $hash1 = {'one' => 1, 'two' => 2}
710 $hash2 = {'two' => 'dos', 'three' => 'tres'}
711 $merged_hash = merge($hash1, $hash2)
712 # The resulting hash is equivalent to:
713 # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
714 ~~~
715
716When there is a duplicate key, the key in the rightmost hash "wins." *Type*: rvalue.
717
718#### `min`
719
720Returns the lowest value of all arguments. Requires at least one argument. *Type*: rvalue.
721
722#### `num2bool`
723
724Converts a number or a string representation of a number into a true boolean. Zero or anything non-numeric becomes 'false'. Numbers greater than 0 become 'true'. *Type*: rvalue.
725
726#### `parsejson`
727
728Converts a string of JSON into the correct Puppet structure. *Type*: rvalue. The optional second argument is returned if the data was not correct.
729
730#### `parseyaml`
731
732Converts a string of YAML into the correct Puppet structure. *Type*: rvalue. The optional second argument is returned if the data was not correct.
733
734#### `pick`
735
736From 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.
737
738 ~~~
739 $real_jenkins_version = pick($::jenkins_version, '1.449')
740 ~~~
741
742*Type*: rvalue.
743
744#### `pick_default`
745
746Returns the first value in a list of values. Contrary to the `pick()` function, the `pick_default()` does not fail if all arguments are empty. This allows it to use an empty value as default. *Type*: rvalue.
747
748#### `prefix`
749
750Applies a prefix to all elements in an array, or to the keys in a hash.
751For example:
752* `prefix(['a','b','c'], 'p')` returns ['pa','pb','pc']
753* `prefix({'a'=>'b','b'=>'c','c'=>'d'}, 'p')` returns {'pa'=>'b','pb'=>'c','pc'=>'d'}.
754
755*Type*: rvalue.
756
757#### `assert_private`
758
759Sets the current class or definition as private. Calling the class or definition from outside the current module will fail.
760
761For example, `assert_private()` called in class `foo::bar` outputs the following message if class is called from outside module `foo`:
762
763 ~~~
764 Class foo::bar is private
765 ~~~
766
767 To specify the error message you want to use:
768
769 ~~~
770 assert_private("You're not supposed to do that!")
771 ~~~
772
773*Type*: statement.
774
775#### `pw_hash`
776
777Hashes a password using the crypt function. Provides a hash usable on most POSIX systems.
778
779The first argument to this function is the password to hash. If it is undef or an empty string, this function returns undef.
780
781The 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:
782
783|Hash type |Specifier|
784|---------------------|---------|
785|MD5 |1 |
786|SHA-256 |5 |
787|SHA-512 (recommended)|6 |
788
789The third argument to this function is the salt to use.
790
791*Type*: rvalue.
792
793**Note:** this 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.
794
795#### `range`
796
797Extrapolates 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].
798
799Non-integer strings are accepted; `range("a", "c")` returns ["a","b","c"], and `range("host01", "host10")` returns ["host01", "host02", ..., "host09", "host10"].
800
801Passing a third argument will cause the generated range to step by that interval, e.g. `range("0", "9", "2")` returns ["0","2","4","6","8"].
802
803*Type*: rvalue.
804
805#### `reject`
806
807Searches through an array and rejects all elements that match the provided regular expression. For example, `reject(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['bbb','ccc']. *Type*: rvalue.
808
809#### `reverse`
810
811Reverses the order of a string or array. *Type*: rvalue.
812
813#### `rstrip`
814
815Strips spaces to the right of the string. *Type*: rvalue.
816
817#### `seeded_rand`
818
819Takes an integer max value and a string seed value and returns a repeatable random integer smaller than max. Like `fqdn_rand`, but does not add node specific data to the seed. *Type*: rvalue.
820
821#### `shuffle`
822
823Randomizes the order of a string or array elements. *Type*: rvalue.
824
825#### `size`
826
827Returns the number of elements in a string, an array or a hash. *Type*: rvalue.
828
829#### `sort`
830
831Sorts strings and arrays lexically. *Type*: rvalue.
832
833#### `squeeze`
834
835Returns a new string where runs of the same character that occur in this set are replaced by a single character. *Type*: rvalue.
836
837#### `str2bool`
838
839Converts certain strings to a boolean. This attempts to convert strings that contain the values '1', 't', 'y', or 'yes' to true. Strings that contain values '0', 'f', 'n', or 'no', or that are an empty string or undefined are converted to false. Any other value causes an error. *Type*: rvalue.
840
841#### `str2saltedsha512`
842
843Converts a string to a salted-SHA512 password hash, used for OS X versions >= 10.7. Given any string, this function returns a hex version of a salted-SHA512 password hash, which can be inserted into your Puppet
844manifests as a valid password attribute. *Type*: rvalue.
845
846#### `strftime`
847
848Returns formatted time. For example, `strftime("%s")` returns the time since Unix epoch, and `strftime("%Y-%m-%d")` returns the date. *Type*: rvalue.
849
850 *Format:*
851
852 * `%a`: The abbreviated weekday name ('Sun')
853 * `%A`: The full weekday name ('Sunday')
854 * `%b`: The abbreviated month name ('Jan')
855 * `%B`: The full month name ('January')
856 * `%c`: The preferred local date and time representation
857 * `%C`: Century (20 in 2009)
858 * `%d`: Day of the month (01..31)
859 * `%D`: Date (%m/%d/%y)
860 * `%e`: Day of the month, blank-padded ( 1..31)
861 * `%F`: Equivalent to %Y-%m-%d (the ISO 8601 date format)
862 * `%h`: Equivalent to %b
863 * `%H`: Hour of the day, 24-hour clock (00..23)
864 * `%I`: Hour of the day, 12-hour clock (01..12)
865 * `%j`: Day of the year (001..366)
866 * `%k`: Hour, 24-hour clock, blank-padded ( 0..23)
867 * `%l`: Hour, 12-hour clock, blank-padded ( 0..12)
868 * `%L`: Millisecond of the second (000..999)
869 * `%m`: Month of the year (01..12)
870 * `%M`: Minute of the hour (00..59)
871 * `%n`: Newline (\n)
872 * `%N`: Fractional seconds digits, default is 9 digits (nanosecond)
873 * `%3N`: Millisecond (3 digits)
874 * `%6N`: Microsecond (6 digits)
875 * `%9N`: Nanosecond (9 digits)
876 * `%p`: Meridian indicator ('AM' or 'PM')
877 * `%P`: Meridian indicator ('am' or 'pm')
878 * `%r`: Time, 12-hour (same as %I:%M:%S %p)
879 * `%R`: Time, 24-hour (%H:%M)
880 * `%s`: Number of seconds since the Unix epoch, 1970-01-01 00:00:00 UTC.
881 * `%S`: Second of the minute (00..60)
882 * `%t`: Tab character ( )
883 * `%T`: Time, 24-hour (%H:%M:%S)
884 * `%u`: Day of the week as a decimal, Monday being 1. (1..7)
885 * `%U`: Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
886 * `%v`: VMS date (%e-%b-%Y)
887 * `%V`: Week number of year according to ISO 8601 (01..53)
888 * `%W`: Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
889 * `%w`: Day of the week (Sunday is 0, 0..6)
890 * `%x`: Preferred representation for the date alone, no time
891 * `%X`: Preferred representation for the time alone, no date
892 * `%y`: Year without a century (00..99)
893 * `%Y`: Year with century
894 * `%z`: Time zone as hour offset from UTC (e.g. +0900)
895 * `%Z`: Time zone name
896 * `%%`: Literal '%' character
897
898#### `strip`
899
900Removes leading and trailing whitespace from a string or from every string inside an array. For example, `strip(" aaa ")` results in "aaa". *Type*: rvalue.
901
902#### `suffix`
903
904Applies a suffix to all elements in an array, or to the keys in a hash.
905For example:
906* `suffix(['a','b','c'], 'p')` returns ['ap','bp','cp']
907* `suffix({'a'=>'b','b'=>'c','c'=>'d'}, 'p')` returns {'ap'=>'b','bp'=>'c','cp'=>'d'}.
908
909*Type*: rvalue.
910
911#### `swapcase`
912
913Swaps the existing case of a string. For example, `swapcase("aBcD")` results in "AbCd". *Type*: rvalue.
914
915#### `time`
916
917Returns the current Unix epoch time as an integer. For example, `time()` returns something like '1311972653'. *Type*: rvalue.
918
919#### `to_bytes`
920
921Converts the argument into bytes, for example "4 kB" becomes "4096". Takes a single string value as an argument. *Type*: rvalue.
922
923#### `try_get_value`
924
925*Type*: rvalue.
926
927DEPRECATED: replaced by `dig()`.
928
929Retrieves a value within multiple layers of hashes and arrays via a string containing a path. The path is a string of hash keys or array indexes starting with zero, separated by the path separator character (default "/"). The function goes through the structure by each path component and tries to return the value at the end of the path.
930
931In 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. The last argument can set the path separator character.
932
933~~~ruby
934$data = {
935 'a' => {
936 'b' => [
937 'b1',
938 'b2',
939 'b3',
940 ]
941 }
942}
943
944$value = try_get_value($data, 'a/b/2')
945# $value = 'b3'
946
947# with all possible options
948$value = try_get_value($data, 'a/b/2', 'not_found', '/')
949# $value = 'b3'
950
951# using the default value
952$value = try_get_value($data, 'a/b/c/d', 'not_found')
953# $value = 'not_found'
954
955# using custom separator
956$value = try_get_value($data, 'a|b', [], '|')
957# $value = ['b1','b2','b3']
958~~~
959
9601. **$data** The data structure we are working with.
9612. **'a/b/2'** The path string.
9623. **'not_found'** The default value. It will be returned if nothing is found.
963 (optional, defaults to *undef*)
9644. **'/'** The path separator character.
965 (optional, defaults to *'/'*)
966
967#### `type3x`
968
969Returns a string description of the type when passed a value. Type can be a string, array, hash, float, integer, or boolean. This function will be removed when Puppet 3 support is dropped and the new type system can be used. *Type*: rvalue.
970
971#### `type_of`
972
973Returns the literal type when passed a value. Requires the new parser. 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] { ... }`) *Type*: rvalue.
974
975#### `union`
976
977Returns a union of two or more arrays, without duplicates. For example, `union(["a","b","c"],["b","c","d"])` returns ["a","b","c","d"]. *Type*: rvalue.
978
979#### `unique`
980
981Removes duplicates from strings and arrays. For example, `unique("aabbcc")` returns 'abc', and `unique(["a","a","b","b","c","c"])` returns ["a","b","c"]. *Type*: rvalue.
982
983#### `unix2dos`
984
985Returns the DOS version of the given string. Very useful when using a File resource with a cross-platform template. *Type*: rvalue.
986
987~~~
988file{$config_file:
989 ensure => file,
990 content => unix2dos(template('my_module/settings.conf.erb')),
991}
992~~~
993
994See also [dos2unix](#dos2unix).
995
996#### `upcase`
997
998Converts an object, array or hash of objects that respond to upcase to uppercase. For example, `upcase('abcd')` returns 'ABCD'. *Type*: rvalue.
999
1000#### `uriescape`
1001
1002URLEncodes a string or array of strings. Requires either a single string or an array as an input. *Type*: rvalue.
1003
1004#### `validate_absolute_path`
1005
1006Validates that a given string represents an absolute path in the filesystem. Works for Windows and Unix style paths.
1007
1008The following values pass:
1009
1010~~~
1011$my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet'
1012validate_absolute_path($my_path)
1013$my_path2 = '/var/lib/puppet'
1014validate_absolute_path($my_path2)
1015$my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet','C:/Program Files/Puppet Labs/Puppet']
1016validate_absolute_path($my_path3)
1017$my_path4 = ['/var/lib/puppet','/usr/share/puppet']
1018validate_absolute_path($my_path4)
1019~~~
1020
1021The following values fail, causing compilation to abort:
1022
1023~~~
1024validate_absolute_path(true)
1025validate_absolute_path('../var/lib/puppet')
1026validate_absolute_path('var/lib/puppet')
1027validate_absolute_path([ 'var/lib/puppet', '/var/foo' ])
1028validate_absolute_path([ '/var/lib/puppet', 'var/foo' ])
1029$undefined = undef
1030validate_absolute_path($undefined)
1031~~~
1032
1033*Type*: statement.
1034
1035#### `validate_array`
1036
1037Validates that all passed values are array data structures. Aborts catalog compilation if any value fails this check.
1038
1039The following values pass:
1040
1041~~~
1042$my_array = [ 'one', 'two' ]
1043validate_array($my_array)
1044~~~
1045
1046The following values fail, causing compilation to abort:
1047
1048~~~
1049validate_array(true)
1050validate_array('some_string')
1051$undefined = undef
1052validate_array($undefined)
1053~~~
1054
1055*Type*: statement.
1056
1057#### `validate_augeas`
1058
1059Performs validation of a string using an Augeas lens. The first argument of this function should be the string to test, and the second argument should be the name of the Augeas lens to use. If Augeas fails to parse the string with the lens, the compilation aborts with a parse error.
1060
1061A third optional argument lists paths which should **not** be found in the file. The `$file` variable points to the location of the temporary file being tested in the Augeas tree.
1062
1063For example, to make sure your $passwdcontent never contains user `foo`:
1064
1065~~~
1066validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
1067~~~
1068
1069To ensure that no users use the '/bin/barsh' shell:
1070
1071~~~
1072validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
1073~~~
1074
1075You can pass a fourth argument as the error message raised and shown to the user:
1076
1077~~~
1078validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas')
1079~~~
1080
1081*Type*: statement.
1082
1083#### `validate_bool`
1084
1085Validates that all passed values are either true or false. Aborts catalog compilation if any value fails this check.
1086
1087The following values will pass:
1088
1089~~~
1090$iamtrue = true
1091validate_bool(true)
1092validate_bool(true, true, false, $iamtrue)
1093~~~
1094
1095The following values will fail, causing compilation to abort:
1096
1097~~~
1098$some_array = [ true ]
1099validate_bool("false")
1100validate_bool("true")
1101validate_bool($some_array)
1102~~~
1103
1104*Type*: statement.
1105
1106#### `validate_cmd`
1107
1108Performs validation of a string with an external command. The first argument of this function should be a string to test, and the second argument should be a path to a test command taking a % as a placeholder for the file path (will default to the end of the command if no % placeholder given). If the command is launched against a tempfile containing the passed string, or returns a non-null value, compilation will abort with a parse error.
1109
1110If a third argument is specified, this will be the error message raised and seen by the user.
1111
1112~~~
1113# Defaults to end of path
1114validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
1115~~~
1116~~~
1117# % as file location
1118validate_cmd($haproxycontent, '/usr/sbin/haproxy -f % -c', 'Haproxy failed to validate config content')
1119~~~
1120
1121*Type*: statement.
1122
1123#### `validate_hash`
1124
1125Validates that all passed values are hash data structures. Aborts catalog compilation if any value fails this check.
1126
1127 The following values will pass:
1128
1129 ~~~
1130 $my_hash = { 'one' => 'two' }
1131 validate_hash($my_hash)
1132 ~~~
1133
1134 The following values will fail, causing compilation to abort:
1135
1136 ~~~
1137 validate_hash(true)
1138 validate_hash('some_string')
1139 $undefined = undef
1140 validate_hash($undefined)
1141 ~~~
1142
1143*Type*: statement.
1144
1145#### `validate_integer`
1146
1147Validates that the first argument is an integer (or an array of integers). Aborts catalog compilation if any of the checks fail.
1148
1149 The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
1150
1151 The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min.
1152 If, and only if, a minimum is given, the second argument may be an empty string or undef, which will be handled to just check
1153 if (all elements of) the first argument are greater or equal to the given minimum.
1154
1155 It will fail if the first argument is not an integer or array of integers, and if arg 2 and arg 3 are not convertable to an integer.
1156
1157 The following values will pass:
1158
1159 ~~~
1160 validate_integer(1)
1161 validate_integer(1, 2)
1162 validate_integer(1, 1)
1163 validate_integer(1, 2, 0)
1164 validate_integer(2, 2, 2)
1165 validate_integer(2, '', 0)
1166 validate_integer(2, undef, 0)
1167 $foo = undef
1168 validate_integer(2, $foo, 0)
1169 validate_integer([1,2,3,4,5], 6)
1170 validate_integer([1,2,3,4,5], 6, 0)
1171 ~~~
1172
1173 * Plus all of the above, but any combination of values passed as strings ('1' or "1").
1174 * Plus all of the above, but with (correct) combinations of negative integer values.
1175
1176 The following values will fail, causing compilation to abort:
1177
1178 ~~~
1179 validate_integer(true)
1180 validate_integer(false)
1181 validate_integer(7.0)
1182 validate_integer({ 1 => 2 })
1183 $foo = undef
1184 validate_integer($foo)
1185 validate_integer($foobaridontexist)
1186
1187 validate_integer(1, 0)
1188 validate_integer(1, true)
1189 validate_integer(1, '')
1190 validate_integer(1, undef)
1191 validate_integer(1, , 0)
1192 validate_integer(1, 2, 3)
1193 validate_integer(1, 3, 2)
1194 validate_integer(1, 3, true)
1195 ~~~
1196
1197 * Plus all of the above, but any combination of values passed as strings ('false' or "false").
1198 * Plus all of the above, but with incorrect combinations of negative integer values.
1199 * Plus all of the above, but with non-integer items in arrays or maximum / minimum argument.
1200
1201 *Type*: statement.
1202
1203#### `validate_ip_address`
1204
1205Validates that the argument is an IP address, regardless of it is an IPv4 or an IPv6
1206address. It also validates IP address with netmask. The argument must be given as a string.
1207
1208The following values will pass:
1209
1210 ~~~
1211 validate_ip_address('0.0.0.0')
1212 validate_ip_address('8.8.8.8')
1213 validate_ip_address('127.0.0.1')
1214 validate_ip_address('194.232.104.150')
1215 validate_ip_address('3ffe:0505:0002::')
1216 validate_ip_address('::1/64')
1217 validate_ip_address('fe80::a00:27ff:fe94:44d6/64')
1218 validate_ip_address('8.8.8.8/32')
1219 ~~~
1220
1221The following values will fail, causing compilation to abort:
1222
1223 ~~~
1224 validate_ip_address(1)
1225 validate_ip_address(true)
1226 validate_ip_address(0.0.0.256)
1227 validate_ip_address('::1', {})
1228 validate_ip_address('0.0.0.0.0')
1229 validate_ip_address('3.3.3')
1230 validate_ip_address('23.43.9.22/64')
1231 validate_ip_address('260.2.32.43')
1232 ~~~
1233
1234
1235#### `validate_numeric`
1236
1237Validates that the first argument is a numeric value (or an array of numeric values). Aborts catalog compilation if any of the checks fail.
1238
1239 The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
1240
1241 The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min.
1242 If, and only if, a minimum is given, the second argument may be an empty string or undef, which will be handled to just check
1243 if (all elements of) the first argument are greater or equal to the given minimum.
1244
1245 It will fail if the first argument is not a numeric (Integer or Float) or array of numerics, and if arg 2 and arg 3 are not convertable to a numeric.
1246
1247 For passing and failing usage, see `validate_integer()`. It is all the same for validate_numeric, yet now floating point values are allowed, too.
1248
1249*Type*: statement.
1250
1251#### `validate_re`
1252
1253Performs simple validation of a string against one or more regular expressions. The first argument of this function should be the string to
1254test, and the second argument should be a stringified regular expression (without the // delimiters) or an array of regular expressions. If none of the regular expressions match the string passed in, compilation aborts with a parse error.
1255
1256 You can pass a third argument as the error message raised and shown to the user.
1257
1258 The following strings validate against the regular expressions:
1259
1260 ~~~
1261 validate_re('one', '^one$')
1262 validate_re('one', [ '^one', '^two' ])
1263 ~~~
1264
1265 The following string fails to validate, causing compilation to abort:
1266
1267 ~~~
1268 validate_re('one', [ '^two', '^three' ])
1269 ~~~
1270
1271 To set the error message:
1272
1273 ~~~
1274 validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
1275 ~~~
1276
1277 Note: Compilation terminates if the first argument is not a string. Always use quotes to force stringification:
1278
1279 ~~~
1280 validate_re("${::operatingsystemmajrelease}", '^[57]$')
1281 ~~~
1282
1283*Type*: statement.
1284
1285#### `validate_slength`
1286
1287Validates that the first argument is a string (or an array of strings), and is less than or equal to the length of the second argument. It fails if the first argument is not a string or array of strings, or if the second argument is not convertable to a number. Optionally, a minimum string length can be given as the third argument.
1288
1289 The following values pass:
1290
1291 ~~~
1292 validate_slength("discombobulate",17)
1293 validate_slength(["discombobulate","moo"],17)
1294 validate_slength(["discombobulate","moo"],17,3)
1295 ~~~
1296
1297 The following values fail:
1298
1299 ~~~
1300 validate_slength("discombobulate",1)
1301 validate_slength(["discombobulate","thermometer"],5)
1302 validate_slength(["discombobulate","moo"],17,10)
1303 ~~~
1304
1305*Type*: statement.
1306
1307#### `validate_string`
1308
1309Validates that all passed values are string data structures. Aborts catalog compilation if any value fails this check.
1310
1311The following values pass:
1312
1313 ~~~
1314 $my_string = "one two"
1315 validate_string($my_string, 'three')
1316 ~~~
1317
1318 The following values fail, causing compilation to abort:
1319
1320 ~~~
1321 validate_string(true)
1322 validate_string([ 'some', 'array' ])
1323 ~~~
1324
1325*Note:* validate_string(undef) will not fail in this version of the functions API (incl. current and future parser).
1326
1327Instead, use:
1328
1329 ~~~
1330 if $var == undef {
1331 fail('...')
1332 }
1333 ~~~
1334
1335*Type*: statement.
1336
1337#### `validate_x509_rsa_key_pair`
1338
1339Validates a PEM-formatted X.509 certificate and private key using OpenSSL.
1340Verifies that the certficate's signature was created from the supplied key.
1341
1342Fails catalog compilation if any value fails this check.
1343
1344Takes two arguments, the first argument must be a X.509 certificate and the
1345second must be an RSA private key:
1346
1347 ~~~
1348 validate_x509_rsa_key_pair($cert, $key)
1349 ~~~
1350
1351*Type*: statement.
1352
1353#### `values`
1354
1355Returns the values of a given hash. For example, given `$hash = {'a'=1, 'b'=2, 'c'=3} values($hash)` returns [1,2,3].
1356
1357*Type*: rvalue.
1358
1359#### `values_at`
1360
1361Finds values inside an array based on location. The first argument is the array you want to analyze, and the second argument can be a combination of:
1362
1363 * A single numeric index
1364 * A range in the form of 'start-stop' (eg. 4-9)
1365 * An array combining the above
1366
1367 For example, `values_at(['a','b','c'], 2)` returns ['c']; `values_at(['a','b','c'], ["0-1"])` returns ['a','b']; and `values_at(['a','b','c','d','e'], [0, "2-3"])` returns ['a','c','d'].
1368
1369*Type*: rvalue.
1370
1371#### `zip`
1372
1373Takes 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.
1374
1375## Limitations
1376
1377As 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.
1378
1379###Version Compatibility
1380
1381Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x |
1382:---------------|:-----:|:---:|:---:|:----:
1383**stdlib 2.x** | **yes** | **yes** | no | no
1384**stdlib 3.x** | no | **yes** | **yes** | no
1385**stdlib 4.x** | no | **yes** | **yes** | no
1386**stdlib 4.6+** | no | **yes** | **yes** | **yes**
1387**stdlib 5.x** | no | no | **yes** | **yes**
1388
1389**stdlib 5.x**: When released, stdlib 5.x will drop support for Puppet 2.7.x. Please see [this discussion](https://github.com/puppetlabs/puppetlabs-stdlib/pull/176#issuecomment-30251414).
1390
1391## Development
1392
1393Puppet Labs 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.puppetlabs.com/forge/contributing.html).
1394
1395To report or research a bug with any part of this module, please go to
1396[http://tickets.puppetlabs.com/browse/PUP](http://tickets.puppetlabs.com/browse/PUP).
1397
1398## Contributors
1399
1400The list of contributors can be found at: [https://github.com/puppetlabs/puppetlabs-stdlib/graphs/contributors](https://github.com/puppetlabs/puppetlabs-stdlib/graphs/contributors).
Note: See TracBrowser for help on using the repository browser.