Mercurial > repos > other > Puppet
comparison modules/stdlib/README.markdown @ 0:956e484adc12
Initial public release of Puppet configs
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 16 Aug 2014 19:47:38 +0000 |
parents | |
children | addb0ea390a1 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:956e484adc12 |
---|---|
1 # Puppet Labs Standard Library # | |
2 | |
3 [![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-stdlib.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-stdlib) | |
4 | |
5 This module provides a "standard library" of resources for developing Puppet | |
6 Modules. This modules will include the following additions to Puppet | |
7 | |
8 * Stages | |
9 * Facts | |
10 * Functions | |
11 * Defined resource types | |
12 * Types | |
13 * Providers | |
14 | |
15 This module is officially curated and provided by Puppet Labs. The modules | |
16 Puppet Labs writes and distributes will make heavy use of this standard | |
17 library. | |
18 | |
19 To report or research a bug with any part of this module, please go to | |
20 [http://projects.puppetlabs.com/projects/stdlib](http://projects.puppetlabs.com/projects/stdlib) | |
21 | |
22 # Versions # | |
23 | |
24 This module follows semver.org (v1.0.0) versioning guidelines. The standard | |
25 library module is released as part of [Puppet | |
26 Enterprise](http://puppetlabs.com/puppet/puppet-enterprise/) and as a result | |
27 older versions of Puppet Enterprise that Puppet Labs still supports will have | |
28 bugfix maintenance branches periodically "merged up" into master. The current | |
29 list of integration branches are: | |
30 | |
31 * v2.1.x (v2.1.1 released in PE 1) | |
32 * v2.2.x (Never released as part of PE, only to the Forge) | |
33 * v2.3.x (Released in PE 2) | |
34 * v3.0.x (Never released as part of PE, only to the Forge) | |
35 * v4.0.x (Drops support for Puppet 2.7) | |
36 * master (mainline development branch) | |
37 | |
38 The first Puppet Enterprise version including the stdlib module is Puppet | |
39 Enterprise 1.2. | |
40 | |
41 # Compatibility # | |
42 | |
43 Puppet Versions | < 2.6 | 2.6 | 2.7 | 3.x | | |
44 :---------------|:-----:|:---:|:---:|:----: | |
45 **stdlib 2.x** | no | **yes** | **yes** | no | |
46 **stdlib 3.x** | no | no | **yes** | **yes** | |
47 **stdlib 4.x** | no | no | no | **yes** | |
48 | |
49 The stdlib module does not work with Puppet versions released prior to Puppet | |
50 2.6.0. | |
51 | |
52 ## stdlib 2.x ## | |
53 | |
54 All stdlib releases in the 2.0 major version support Puppet 2.6 and Puppet 2.7. | |
55 | |
56 ## stdlib 3.x ## | |
57 | |
58 The 3.0 major release of stdlib drops support for Puppet 2.6. Stdlib 3.x | |
59 supports Puppet 2 and Puppet 3. | |
60 | |
61 ## stdlib 4.x ## | |
62 | |
63 The 4.0 major release of stdlib drops support for Puppet 2.7. Stdlib 4.x | |
64 supports Puppet 3. Notably, ruby 1.8.5 is no longer supported though ruby | |
65 1.8.7, 1.9.3, and 2.0.0 are fully supported. | |
66 | |
67 # Functions # | |
68 | |
69 abs | |
70 --- | |
71 Returns the absolute value of a number, for example -34.56 becomes | |
72 34.56. Takes a single integer and float value as an argument. | |
73 | |
74 | |
75 - *Type*: rvalue | |
76 | |
77 any2array | |
78 --------- | |
79 This converts any object to an array containing that object. Empty argument | |
80 lists are converted to an empty array. Arrays are left untouched. Hashes are | |
81 converted to arrays of alternating keys and values. | |
82 | |
83 | |
84 - *Type*: rvalue | |
85 | |
86 bool2num | |
87 -------- | |
88 Converts a boolean to a number. Converts the values: | |
89 false, f, 0, n, and no to 0 | |
90 true, t, 1, y, and yes to 1 | |
91 Requires a single boolean or string as an input. | |
92 | |
93 | |
94 - *Type*: rvalue | |
95 | |
96 capitalize | |
97 ---------- | |
98 Capitalizes the first letter of a string or array of strings. | |
99 Requires either a single string or an array as an input. | |
100 | |
101 | |
102 - *Type*: rvalue | |
103 | |
104 chomp | |
105 ----- | |
106 Removes the record separator from the end of a string or an array of | |
107 strings, for example `hello\n` becomes `hello`. | |
108 Requires a single string or array as an input. | |
109 | |
110 | |
111 - *Type*: rvalue | |
112 | |
113 chop | |
114 ---- | |
115 Returns a new string with the last character removed. If the string ends | |
116 with `\r\n`, both characters are removed. Applying chop to an empty | |
117 string returns an empty string. If you wish to merely remove record | |
118 separators then you should use the `chomp` function. | |
119 Requires a string or array of strings as input. | |
120 | |
121 | |
122 - *Type*: rvalue | |
123 | |
124 concat | |
125 ------ | |
126 Appends the contents of array 2 onto array 1. | |
127 | |
128 *Example:* | |
129 | |
130 concat(['1','2','3'],['4','5','6']) | |
131 | |
132 Would result in: | |
133 | |
134 ['1','2','3','4','5','6'] | |
135 | |
136 | |
137 - *Type*: rvalue | |
138 | |
139 count | |
140 ----- | |
141 Takes an array as first argument and an optional second argument. | |
142 Count the number of elements in array that matches second argument. | |
143 If called with only an array it counts the number of elements that are not nil/undef. | |
144 | |
145 | |
146 - *Type*: rvalue | |
147 | |
148 defined_with_params | |
149 ------------------- | |
150 Takes a resource reference and an optional hash of attributes. | |
151 | |
152 Returns true if a resource with the specified attributes has already been added | |
153 to the catalog, and false otherwise. | |
154 | |
155 user { 'dan': | |
156 ensure => present, | |
157 } | |
158 | |
159 if ! defined_with_params(User[dan], {'ensure' => 'present' }) { | |
160 user { 'dan': ensure => present, } | |
161 } | |
162 | |
163 | |
164 - *Type*: rvalue | |
165 | |
166 delete | |
167 ------ | |
168 Deletes all instances of a given element from an array, substring from a | |
169 string, or key from a hash. | |
170 | |
171 *Examples:* | |
172 | |
173 delete(['a','b','c','b'], 'b') | |
174 Would return: ['a','c'] | |
175 | |
176 delete({'a'=>1,'b'=>2,'c'=>3}, 'b') | |
177 Would return: {'a'=>1,'c'=>3} | |
178 | |
179 delete('abracadabra', 'bra') | |
180 Would return: 'acada' | |
181 | |
182 | |
183 - *Type*: rvalue | |
184 | |
185 delete_at | |
186 --------- | |
187 Deletes a determined indexed value from an array. | |
188 | |
189 *Examples:* | |
190 | |
191 delete_at(['a','b','c'], 1) | |
192 | |
193 Would return: ['a','c'] | |
194 | |
195 | |
196 - *Type*: rvalue | |
197 | |
198 dirname | |
199 ------- | |
200 Returns the `dirname` of a path. | |
201 | |
202 *Examples:* | |
203 | |
204 dirname('/path/to/a/file.ext') | |
205 | |
206 Would return: '/path/to/a' | |
207 | |
208 downcase | |
209 -------- | |
210 Converts the case of a string or all strings in an array to lower case. | |
211 | |
212 | |
213 - *Type*: rvalue | |
214 | |
215 empty | |
216 ----- | |
217 Returns true if the variable is empty. | |
218 | |
219 | |
220 - *Type*: rvalue | |
221 | |
222 ensure_packages | |
223 --------------- | |
224 Takes a list of packages and only installs them if they don't already exist. | |
225 | |
226 | |
227 - *Type*: statement | |
228 | |
229 ensure_resource | |
230 --------------- | |
231 Takes a resource type, title, and a list of attributes that describe a | |
232 resource. | |
233 | |
234 user { 'dan': | |
235 ensure => present, | |
236 } | |
237 | |
238 This example only creates the resource if it does not already exist: | |
239 | |
240 ensure_resource('user, 'dan', {'ensure' => 'present' }) | |
241 | |
242 If the resource already exists but does not match the specified parameters, | |
243 this function will attempt to recreate the resource leading to a duplicate | |
244 resource definition error. | |
245 | |
246 An array of resources can also be passed in and each will be created with | |
247 the type and parameters specified if it doesn't already exist. | |
248 | |
249 ensure_resource('user', ['dan','alex'], {'ensure' => 'present'}) | |
250 | |
251 | |
252 | |
253 - *Type*: statement | |
254 | |
255 flatten | |
256 ------- | |
257 This function flattens any deeply nested arrays and returns a single flat array | |
258 as a result. | |
259 | |
260 *Examples:* | |
261 | |
262 flatten(['a', ['b', ['c']]]) | |
263 | |
264 Would return: ['a','b','c'] | |
265 | |
266 | |
267 - *Type*: rvalue | |
268 | |
269 floor | |
270 ----- | |
271 Returns the largest integer less or equal to the argument. | |
272 Takes a single numeric value as an argument. | |
273 | |
274 | |
275 - *Type*: rvalue | |
276 | |
277 fqdn_rotate | |
278 ----------- | |
279 Rotates an array a random number of times based on a nodes fqdn. | |
280 | |
281 | |
282 - *Type*: rvalue | |
283 | |
284 get_module_path | |
285 --------------- | |
286 Returns the absolute path of the specified module for the current | |
287 environment. | |
288 | |
289 Example: | |
290 $module_path = get_module_path('stdlib') | |
291 | |
292 | |
293 - *Type*: rvalue | |
294 | |
295 getparam | |
296 -------- | |
297 Takes a resource reference and name of the parameter and | |
298 returns value of resource's parameter. | |
299 | |
300 *Examples:* | |
301 | |
302 define example_resource($param) { | |
303 } | |
304 | |
305 example_resource { "example_resource_instance": | |
306 param => "param_value" | |
307 } | |
308 | |
309 getparam(Example_resource["example_resource_instance"], "param") | |
310 | |
311 Would return: param_value | |
312 | |
313 | |
314 - *Type*: rvalue | |
315 | |
316 getvar | |
317 ------ | |
318 Lookup a variable in a remote namespace. | |
319 | |
320 For example: | |
321 | |
322 $foo = getvar('site::data::foo') | |
323 # Equivalent to $foo = $site::data::foo | |
324 | |
325 This is useful if the namespace itself is stored in a string: | |
326 | |
327 $datalocation = 'site::data' | |
328 $bar = getvar("${datalocation}::bar") | |
329 # Equivalent to $bar = $site::data::bar | |
330 | |
331 | |
332 - *Type*: rvalue | |
333 | |
334 grep | |
335 ---- | |
336 This function searches through an array and returns any elements that match | |
337 the provided regular expression. | |
338 | |
339 *Examples:* | |
340 | |
341 grep(['aaa','bbb','ccc','aaaddd'], 'aaa') | |
342 | |
343 Would return: | |
344 | |
345 ['aaa','aaaddd'] | |
346 | |
347 | |
348 - *Type*: rvalue | |
349 | |
350 has_interface_with | |
351 ------------------ | |
352 Returns boolean based on kind and value: | |
353 * macaddress | |
354 * netmask | |
355 * ipaddress | |
356 * network | |
357 | |
358 has_interface_with("macaddress", "x:x:x:x:x:x") | |
359 has_interface_with("ipaddress", "127.0.0.1") => true | |
360 etc. | |
361 | |
362 If no "kind" is given, then the presence of the interface is checked: | |
363 has_interface_with("lo") => true | |
364 | |
365 | |
366 - *Type*: rvalue | |
367 | |
368 has_ip_address | |
369 -------------- | |
370 Returns true if the client has the requested IP address on some interface. | |
371 | |
372 This function iterates through the 'interfaces' fact and checks the | |
373 'ipaddress_IFACE' facts, performing a simple string comparison. | |
374 | |
375 | |
376 - *Type*: rvalue | |
377 | |
378 has_ip_network | |
379 -------------- | |
380 Returns true if the client has an IP address within the requested network. | |
381 | |
382 This function iterates through the 'interfaces' fact and checks the | |
383 'network_IFACE' facts, performing a simple string comparision. | |
384 | |
385 | |
386 - *Type*: rvalue | |
387 | |
388 has_key | |
389 ------- | |
390 Determine if a hash has a certain key value. | |
391 | |
392 Example: | |
393 | |
394 $my_hash = {'key_one' => 'value_one'} | |
395 if has_key($my_hash, 'key_two') { | |
396 notice('we will not reach here') | |
397 } | |
398 if has_key($my_hash, 'key_one') { | |
399 notice('this will be printed') | |
400 } | |
401 | |
402 | |
403 | |
404 - *Type*: rvalue | |
405 | |
406 hash | |
407 ---- | |
408 This function converts an array into a hash. | |
409 | |
410 *Examples:* | |
411 | |
412 hash(['a',1,'b',2,'c',3]) | |
413 | |
414 Would return: {'a'=>1,'b'=>2,'c'=>3} | |
415 | |
416 | |
417 - *Type*: rvalue | |
418 | |
419 is_array | |
420 -------- | |
421 Returns true if the variable passed to this function is an array. | |
422 | |
423 - *Type*: rvalue | |
424 | |
425 is_domain_name | |
426 -------------- | |
427 Returns true if the string passed to this function is a syntactically correct domain name. | |
428 | |
429 - *Type*: rvalue | |
430 | |
431 is_float | |
432 -------- | |
433 Returns true if the variable passed to this function is a float. | |
434 | |
435 - *Type*: rvalue | |
436 | |
437 is_function_available | |
438 --------------------- | |
439 This function accepts a string as an argument, determines whether the | |
440 Puppet runtime has access to a function by that name. It returns a | |
441 true if the function exists, false if not. | |
442 | |
443 - *Type*: rvalue | |
444 | |
445 is_hash | |
446 ------- | |
447 Returns true if the variable passed to this function is a hash. | |
448 | |
449 - *Type*: rvalue | |
450 | |
451 is_integer | |
452 ---------- | |
453 Returns true if the variable returned to this string is an integer. | |
454 | |
455 - *Type*: rvalue | |
456 | |
457 is_ip_address | |
458 ------------- | |
459 Returns true if the string passed to this function is a valid IP address. | |
460 | |
461 - *Type*: rvalue | |
462 | |
463 is_mac_address | |
464 -------------- | |
465 Returns true if the string passed to this function is a valid mac address. | |
466 | |
467 - *Type*: rvalue | |
468 | |
469 is_numeric | |
470 ---------- | |
471 Returns true if the variable passed to this function is a number. | |
472 | |
473 - *Type*: rvalue | |
474 | |
475 is_string | |
476 --------- | |
477 Returns true if the variable passed to this function is a string. | |
478 | |
479 - *Type*: rvalue | |
480 | |
481 join | |
482 ---- | |
483 This function joins an array into a string using a seperator. | |
484 | |
485 *Examples:* | |
486 | |
487 join(['a','b','c'], ",") | |
488 | |
489 Would result in: "a,b,c" | |
490 | |
491 - *Type*: rvalue | |
492 | |
493 join_keys_to_values | |
494 ------------------- | |
495 This function joins each key of a hash to that key's corresponding value with a | |
496 separator. Keys and values are cast to strings. The return value is an array in | |
497 which each element is one joined key/value pair. | |
498 | |
499 *Examples:* | |
500 | |
501 join_keys_to_values({'a'=>1,'b'=>2}, " is ") | |
502 | |
503 Would result in: ["a is 1","b is 2"] | |
504 | |
505 - *Type*: rvalue | |
506 | |
507 keys | |
508 ---- | |
509 Returns the keys of a hash as an array. | |
510 | |
511 - *Type*: rvalue | |
512 | |
513 loadyaml | |
514 -------- | |
515 Load a YAML file containing an array, string, or hash, and return the data | |
516 in the corresponding native data type. | |
517 | |
518 For example: | |
519 | |
520 $myhash = loadyaml('/etc/puppet/data/myhash.yaml') | |
521 | |
522 | |
523 - *Type*: rvalue | |
524 | |
525 lstrip | |
526 ------ | |
527 Strips leading spaces to the left of a string. | |
528 | |
529 - *Type*: rvalue | |
530 | |
531 max | |
532 --- | |
533 Returns the highest value of all arguments. | |
534 Requires at least one argument. | |
535 | |
536 - *Type*: rvalue | |
537 | |
538 member | |
539 ------ | |
540 This function determines if a variable is a member of an array. | |
541 | |
542 *Examples:* | |
543 | |
544 member(['a','b'], 'b') | |
545 | |
546 Would return: true | |
547 | |
548 member(['a','b'], 'c') | |
549 | |
550 Would return: false | |
551 | |
552 - *Type*: rvalue | |
553 | |
554 merge | |
555 ----- | |
556 Merges two or more hashes together and returns the resulting hash. | |
557 | |
558 For example: | |
559 | |
560 $hash1 = {'one' => 1, 'two', => 2} | |
561 $hash2 = {'two' => 'dos', 'three', => 'tres'} | |
562 $merged_hash = merge($hash1, $hash2) | |
563 # The resulting hash is equivalent to: | |
564 # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} | |
565 | |
566 When there is a duplicate key, the key in the rightmost hash will "win." | |
567 | |
568 - *Type*: rvalue | |
569 | |
570 min | |
571 --- | |
572 Returns the lowest value of all arguments. | |
573 Requires at least one argument. | |
574 | |
575 - *Type*: rvalue | |
576 | |
577 num2bool | |
578 -------- | |
579 This function converts a number or a string representation of a number into a | |
580 true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0 | |
581 become true. | |
582 | |
583 - *Type*: rvalue | |
584 | |
585 parsejson | |
586 --------- | |
587 This function accepts JSON as a string and converts into the correct Puppet | |
588 structure. | |
589 | |
590 - *Type*: rvalue | |
591 | |
592 parseyaml | |
593 --------- | |
594 This function accepts YAML as a string and converts it into the correct | |
595 Puppet structure. | |
596 | |
597 - *Type*: rvalue | |
598 | |
599 pick | |
600 ---- | |
601 This function is similar to a coalesce function in SQL in that it will return | |
602 the first value in a list of values that is not undefined or an empty string | |
603 (two things in Puppet that will return a boolean false value). Typically, | |
604 this function is used to check for a value in the Puppet Dashboard/Enterprise | |
605 Console, and failover to a default value like the following: | |
606 | |
607 $real_jenkins_version = pick($::jenkins_version, '1.449') | |
608 | |
609 The value of $real_jenkins_version will first look for a top-scope variable | |
610 called 'jenkins_version' (note that parameters set in the Puppet Dashboard/ | |
611 Enterprise Console are brought into Puppet as top-scope variables), and, | |
612 failing that, will use a default value of 1.449. | |
613 | |
614 - *Type*: rvalue | |
615 | |
616 prefix | |
617 ------ | |
618 This function applies a prefix to all elements in an array. | |
619 | |
620 *Examples:* | |
621 | |
622 prefix(['a','b','c'], 'p') | |
623 | |
624 Will return: ['pa','pb','pc'] | |
625 | |
626 - *Type*: rvalue | |
627 | |
628 range | |
629 ----- | |
630 When given range in the form of (start, stop) it will extrapolate a range as | |
631 an array. | |
632 | |
633 *Examples:* | |
634 | |
635 range("0", "9") | |
636 | |
637 Will return: [0,1,2,3,4,5,6,7,8,9] | |
638 | |
639 range("00", "09") | |
640 | |
641 Will return: [0,1,2,3,4,5,6,7,8,9] (Zero padded strings are converted to | |
642 integers automatically) | |
643 | |
644 range("a", "c") | |
645 | |
646 Will return: ["a","b","c"] | |
647 | |
648 range("host01", "host10") | |
649 | |
650 Will return: ["host01", "host02", ..., "host09", "host10"] | |
651 | |
652 - *Type*: rvalue | |
653 | |
654 reject | |
655 ------ | |
656 This function searches through an array and rejects all elements that match | |
657 the provided regular expression. | |
658 | |
659 *Examples:* | |
660 | |
661 reject(['aaa','bbb','ccc','aaaddd'], 'aaa') | |
662 | |
663 Would return: | |
664 | |
665 ['bbb','ccc'] | |
666 | |
667 | |
668 - *Type*: rvalue | |
669 | |
670 reverse | |
671 ------- | |
672 Reverses the order of a string or array. | |
673 | |
674 - *Type*: rvalue | |
675 | |
676 rstrip | |
677 ------ | |
678 Strips leading spaces to the right of the string. | |
679 | |
680 - *Type*: rvalue | |
681 | |
682 shuffle | |
683 ------- | |
684 Randomizes the order of a string or array elements. | |
685 | |
686 - *Type*: rvalue | |
687 | |
688 size | |
689 ---- | |
690 Returns the number of elements in a string or array. | |
691 | |
692 - *Type*: rvalue | |
693 | |
694 sort | |
695 ---- | |
696 Sorts strings and arrays lexically. | |
697 | |
698 - *Type*: rvalue | |
699 | |
700 squeeze | |
701 ------- | |
702 Returns a new string where runs of the same character that occur in this set | |
703 are replaced by a single character. | |
704 | |
705 - *Type*: rvalue | |
706 | |
707 str2bool | |
708 -------- | |
709 This converts a string to a boolean. This attempt to convert strings that | |
710 contain things like: y, 1, t, true to 'true' and strings that contain things | |
711 like: 0, f, n, false, no to 'false'. | |
712 | |
713 | |
714 - *Type*: rvalue | |
715 | |
716 str2saltedsha512 | |
717 ---------------- | |
718 This converts a string to a salted-SHA512 password hash (which is used for | |
719 OS X versions >= 10.7). Given any simple string, you will get a hex version | |
720 of a salted-SHA512 password hash that can be inserted into your Puppet | |
721 manifests as a valid password attribute. | |
722 | |
723 | |
724 - *Type*: rvalue | |
725 | |
726 strftime | |
727 -------- | |
728 This function returns formatted time. | |
729 | |
730 *Examples:* | |
731 | |
732 To return the time since epoch: | |
733 | |
734 strftime("%s") | |
735 | |
736 To return the date: | |
737 | |
738 strftime("%Y-%m-%d") | |
739 | |
740 *Format meaning:* | |
741 | |
742 %a - The abbreviated weekday name (``Sun'') | |
743 %A - The full weekday name (``Sunday'') | |
744 %b - The abbreviated month name (``Jan'') | |
745 %B - The full month name (``January'') | |
746 %c - The preferred local date and time representation | |
747 %C - Century (20 in 2009) | |
748 %d - Day of the month (01..31) | |
749 %D - Date (%m/%d/%y) | |
750 %e - Day of the month, blank-padded ( 1..31) | |
751 %F - Equivalent to %Y-%m-%d (the ISO 8601 date format) | |
752 %h - Equivalent to %b | |
753 %H - Hour of the day, 24-hour clock (00..23) | |
754 %I - Hour of the day, 12-hour clock (01..12) | |
755 %j - Day of the year (001..366) | |
756 %k - hour, 24-hour clock, blank-padded ( 0..23) | |
757 %l - hour, 12-hour clock, blank-padded ( 0..12) | |
758 %L - Millisecond of the second (000..999) | |
759 %m - Month of the year (01..12) | |
760 %M - Minute of the hour (00..59) | |
761 %n - Newline ( | |
762 ) | |
763 %N - Fractional seconds digits, default is 9 digits (nanosecond) | |
764 %3N millisecond (3 digits) | |
765 %6N microsecond (6 digits) | |
766 %9N nanosecond (9 digits) | |
767 %p - Meridian indicator (``AM'' or ``PM'') | |
768 %P - Meridian indicator (``am'' or ``pm'') | |
769 %r - time, 12-hour (same as %I:%M:%S %p) | |
770 %R - time, 24-hour (%H:%M) | |
771 %s - Number of seconds since 1970-01-01 00:00:00 UTC. | |
772 %S - Second of the minute (00..60) | |
773 %t - Tab character ( ) | |
774 %T - time, 24-hour (%H:%M:%S) | |
775 %u - Day of the week as a decimal, Monday being 1. (1..7) | |
776 %U - Week number of the current year, | |
777 starting with the first Sunday as the first | |
778 day of the first week (00..53) | |
779 %v - VMS date (%e-%b-%Y) | |
780 %V - Week number of year according to ISO 8601 (01..53) | |
781 %W - Week number of the current year, | |
782 starting with the first Monday as the first | |
783 day of the first week (00..53) | |
784 %w - Day of the week (Sunday is 0, 0..6) | |
785 %x - Preferred representation for the date alone, no time | |
786 %X - Preferred representation for the time alone, no date | |
787 %y - Year without a century (00..99) | |
788 %Y - Year with century | |
789 %z - Time zone as hour offset from UTC (e.g. +0900) | |
790 %Z - Time zone name | |
791 %% - Literal ``%'' character | |
792 | |
793 | |
794 - *Type*: rvalue | |
795 | |
796 strip | |
797 ----- | |
798 This function removes leading and trailing whitespace from a string or from | |
799 every string inside an array. | |
800 | |
801 *Examples:* | |
802 | |
803 strip(" aaa ") | |
804 | |
805 Would result in: "aaa" | |
806 | |
807 | |
808 - *Type*: rvalue | |
809 | |
810 suffix | |
811 ------ | |
812 This function applies a suffix to all elements in an array. | |
813 | |
814 *Examples:* | |
815 | |
816 suffix(['a','b','c'], 'p') | |
817 | |
818 Will return: ['ap','bp','cp'] | |
819 | |
820 | |
821 - *Type*: rvalue | |
822 | |
823 swapcase | |
824 -------- | |
825 This function will swap the existing case of a string. | |
826 | |
827 *Examples:* | |
828 | |
829 swapcase("aBcD") | |
830 | |
831 Would result in: "AbCd" | |
832 | |
833 | |
834 - *Type*: rvalue | |
835 | |
836 time | |
837 ---- | |
838 This function will return the current time since epoch as an integer. | |
839 | |
840 *Examples:* | |
841 | |
842 time() | |
843 | |
844 Will return something like: 1311972653 | |
845 | |
846 | |
847 - *Type*: rvalue | |
848 | |
849 to_bytes | |
850 -------- | |
851 Converts the argument into bytes, for example 4 kB becomes 4096. | |
852 Takes a single string value as an argument. | |
853 | |
854 | |
855 - *Type*: rvalue | |
856 | |
857 type | |
858 ---- | |
859 Returns the type when passed a variable. Type can be one of: | |
860 | |
861 * string | |
862 * array | |
863 * hash | |
864 * float | |
865 * integer | |
866 * boolean | |
867 | |
868 | |
869 - *Type*: rvalue | |
870 | |
871 unique | |
872 ------ | |
873 This function will remove duplicates from strings and arrays. | |
874 | |
875 *Examples:* | |
876 | |
877 unique("aabbcc") | |
878 | |
879 Will return: | |
880 | |
881 abc | |
882 | |
883 You can also use this with arrays: | |
884 | |
885 unique(["a","a","b","b","c","c"]) | |
886 | |
887 This returns: | |
888 | |
889 ["a","b","c"] | |
890 | |
891 | |
892 - *Type*: rvalue | |
893 | |
894 upcase | |
895 ------ | |
896 Converts a string or an array of strings to uppercase. | |
897 | |
898 *Examples:* | |
899 | |
900 upcase("abcd") | |
901 | |
902 Will return: | |
903 | |
904 ASDF | |
905 | |
906 | |
907 - *Type*: rvalue | |
908 | |
909 uriescape | |
910 --------- | |
911 Urlencodes a string or array of strings. | |
912 Requires either a single string or an array as an input. | |
913 | |
914 | |
915 - *Type*: rvalue | |
916 | |
917 validate_absolute_path | |
918 ---------------------- | |
919 Validate the string represents an absolute path in the filesystem. This function works | |
920 for windows and unix style paths. | |
921 | |
922 The following values will pass: | |
923 | |
924 $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet" | |
925 validate_absolute_path($my_path) | |
926 $my_path2 = "/var/lib/puppet" | |
927 validate_absolute_path($my_path2) | |
928 | |
929 | |
930 The following values will fail, causing compilation to abort: | |
931 | |
932 validate_absolute_path(true) | |
933 validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) | |
934 validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) | |
935 $undefined = undef | |
936 validate_absolute_path($undefined) | |
937 | |
938 | |
939 | |
940 - *Type*: statement | |
941 | |
942 validate_array | |
943 -------------- | |
944 Validate that all passed values are array data structures. Abort catalog | |
945 compilation if any value fails this check. | |
946 | |
947 The following values will pass: | |
948 | |
949 $my_array = [ 'one', 'two' ] | |
950 validate_array($my_array) | |
951 | |
952 The following values will fail, causing compilation to abort: | |
953 | |
954 validate_array(true) | |
955 validate_array('some_string') | |
956 $undefined = undef | |
957 validate_array($undefined) | |
958 | |
959 | |
960 | |
961 - *Type*: statement | |
962 | |
963 validate_augeas | |
964 --------------- | |
965 Perform validation of a string using an Augeas lens | |
966 The first argument of this function should be a string to | |
967 test, and the second argument should be the name of the Augeas lens to use. | |
968 If Augeas fails to parse the string with the lens, the compilation will | |
969 abort with a parse error. | |
970 | |
971 A third argument can be specified, listing paths which should | |
972 not be found in the file. The `$file` variable points to the location | |
973 of the temporary file being tested in the Augeas tree. | |
974 | |
975 For example, if you want to make sure your passwd content never contains | |
976 a user `foo`, you could write: | |
977 | |
978 validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo']) | |
979 | |
980 Or if you wanted to ensure that no users used the '/bin/barsh' shell, | |
981 you could use: | |
982 | |
983 validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]'] | |
984 | |
985 If a fourth argument is specified, this will be the error message raised and | |
986 seen by the user. | |
987 | |
988 A helpful error message can be returned like this: | |
989 | |
990 validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas') | |
991 | |
992 | |
993 | |
994 - *Type*: statement | |
995 | |
996 validate_bool | |
997 ------------- | |
998 Validate that all passed values are either true or false. Abort catalog | |
999 compilation if any value fails this check. | |
1000 | |
1001 The following values will pass: | |
1002 | |
1003 $iamtrue = true | |
1004 validate_bool(true) | |
1005 validate_bool(true, true, false, $iamtrue) | |
1006 | |
1007 The following values will fail, causing compilation to abort: | |
1008 | |
1009 $some_array = [ true ] | |
1010 validate_bool("false") | |
1011 validate_bool("true") | |
1012 validate_bool($some_array) | |
1013 | |
1014 | |
1015 | |
1016 - *Type*: statement | |
1017 | |
1018 validate_cmd | |
1019 ------------ | |
1020 Perform validation of a string with an external command. | |
1021 The first argument of this function should be a string to | |
1022 test, and the second argument should be a path to a test command | |
1023 taking a file as last argument. If the command, launched against | |
1024 a tempfile containing the passed string, returns a non-null value, | |
1025 compilation will abort with a parse error. | |
1026 | |
1027 If a third argument is specified, this will be the error message raised and | |
1028 seen by the user. | |
1029 | |
1030 A helpful error message can be returned like this: | |
1031 | |
1032 Example: | |
1033 | |
1034 validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content') | |
1035 | |
1036 | |
1037 | |
1038 - *Type*: statement | |
1039 | |
1040 validate_hash | |
1041 ------------- | |
1042 Validate that all passed values are hash data structures. Abort catalog | |
1043 compilation if any value fails this check. | |
1044 | |
1045 The following values will pass: | |
1046 | |
1047 $my_hash = { 'one' => 'two' } | |
1048 validate_hash($my_hash) | |
1049 | |
1050 The following values will fail, causing compilation to abort: | |
1051 | |
1052 validate_hash(true) | |
1053 validate_hash('some_string') | |
1054 $undefined = undef | |
1055 validate_hash($undefined) | |
1056 | |
1057 | |
1058 | |
1059 - *Type*: statement | |
1060 | |
1061 validate_re | |
1062 ----------- | |
1063 Perform simple validation of a string against one or more regular | |
1064 expressions. The first argument of this function should be a string to | |
1065 test, and the second argument should be a stringified regular expression | |
1066 (without the // delimiters) or an array of regular expressions. If none | |
1067 of the regular expressions match the string passed in, compilation will | |
1068 abort with a parse error. | |
1069 | |
1070 If a third argument is specified, this will be the error message raised and | |
1071 seen by the user. | |
1072 | |
1073 The following strings will validate against the regular expressions: | |
1074 | |
1075 validate_re('one', '^one$') | |
1076 validate_re('one', [ '^one', '^two' ]) | |
1077 | |
1078 The following strings will fail to validate, causing compilation to abort: | |
1079 | |
1080 validate_re('one', [ '^two', '^three' ]) | |
1081 | |
1082 A helpful error message can be returned like this: | |
1083 | |
1084 validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7') | |
1085 | |
1086 | |
1087 | |
1088 - *Type*: statement | |
1089 | |
1090 validate_slength | |
1091 ---------------- | |
1092 Validate that the first argument is a string (or an array of strings), and | |
1093 less/equal to than the length of the second argument. It fails if the first | |
1094 argument is not a string or array of strings, and if arg 2 is not convertable | |
1095 to a number. | |
1096 | |
1097 The following values will pass: | |
1098 | |
1099 validate_slength("discombobulate",17) | |
1100 validate_slength(["discombobulate","moo"],17) | |
1101 | |
1102 The following valueis will not: | |
1103 | |
1104 validate_slength("discombobulate",1) | |
1105 validate_slength(["discombobulate","thermometer"],5) | |
1106 | |
1107 | |
1108 | |
1109 - *Type*: statement | |
1110 | |
1111 validate_string | |
1112 --------------- | |
1113 Validate that all passed values are string data structures. Abort catalog | |
1114 compilation if any value fails this check. | |
1115 | |
1116 The following values will pass: | |
1117 | |
1118 $my_string = "one two" | |
1119 validate_string($my_string, 'three') | |
1120 | |
1121 The following values will fail, causing compilation to abort: | |
1122 | |
1123 validate_string(true) | |
1124 validate_string([ 'some', 'array' ]) | |
1125 $undefined = undef | |
1126 validate_string($undefined) | |
1127 | |
1128 | |
1129 - *Type*: statement | |
1130 | |
1131 values | |
1132 ------ | |
1133 When given a hash this function will return the values of that hash. | |
1134 | |
1135 *Examples:* | |
1136 | |
1137 $hash = { | |
1138 'a' => 1, | |
1139 'b' => 2, | |
1140 'c' => 3, | |
1141 } | |
1142 values($hash) | |
1143 | |
1144 This example would return: | |
1145 | |
1146 [1,2,3] | |
1147 | |
1148 | |
1149 - *Type*: rvalue | |
1150 | |
1151 values_at | |
1152 --------- | |
1153 Finds value inside an array based on location. | |
1154 | |
1155 The first argument is the array you want to analyze, and the second element can | |
1156 be a combination of: | |
1157 | |
1158 * A single numeric index | |
1159 * A range in the form of 'start-stop' (eg. 4-9) | |
1160 * An array combining the above | |
1161 | |
1162 *Examples*: | |
1163 | |
1164 values_at(['a','b','c'], 2) | |
1165 | |
1166 Would return ['c']. | |
1167 | |
1168 values_at(['a','b','c'], ["0-1"]) | |
1169 | |
1170 Would return ['a','b']. | |
1171 | |
1172 values_at(['a','b','c','d','e'], [0, "2-3"]) | |
1173 | |
1174 Would return ['a','c','d']. | |
1175 | |
1176 | |
1177 - *Type*: rvalue | |
1178 | |
1179 zip | |
1180 --- | |
1181 Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments. | |
1182 | |
1183 *Example:* | |
1184 | |
1185 zip(['1','2','3'],['4','5','6']) | |
1186 | |
1187 Would result in: | |
1188 | |
1189 ["1", "4"], ["2", "5"], ["3", "6"] | |
1190 | |
1191 | |
1192 - *Type*: rvalue | |
1193 | |
1194 *This page autogenerated on 2013-04-11 13:54:25 -0700* |