PageRenderTime 26ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/source/references/2.6.0/function.markdown

https://github.com/djm68/puppet-docs
Markdown | 338 lines | 216 code | 122 blank | 0 comment | 0 complexity | bd35c84714fc0dff6f540bb49620066b MD5 | raw file
  1. % Function Reference
  2. %
  3. %
  4. **This page is autogenerated; any changes will get overwritten**
  5. *(last generated on Mon Jul 19 21:53:31 -0700 2010)*
  6. There are two types of functions in Puppet: Statements and rvalues.
  7. Statements stand on their own and do not return arguments; they are
  8. used for performing stand-alone work like importing. Rvalues return
  9. values and can only be used in a statement requiring a value, such
  10. as an assignment or a case statement.
  11. Here are the functions available in Puppet:
  12. # alert
  13. Log a message on the server at level alert.
  14. - **Type**: statement
  15. # crit
  16. Log a message on the server at level crit.
  17. - **Type**: statement
  18. # debug
  19. Log a message on the server at level debug.
  20. - **Type**: statement
  21. # defined
  22. Determine whether a given type is defined, either as a native type
  23. or a defined type, or whether a class is defined. This is useful
  24. for checking whether a class is defined and only including it if it
  25. is. This function can also test whether a resource has been
  26. defined, using resource references (e.g.,
  27. `if defined(File['/tmp/myfile']) { ... }`). This function is
  28. unfortunately dependent on the parse order of the configuration
  29. when testing whether a resource is defined.
  30. - **Type**: rvalue
  31. # emerg
  32. Log a message on the server at level emerg.
  33. - **Type**: statement
  34. # err
  35. Log a message on the server at level err.
  36. - **Type**: statement
  37. # fail
  38. Fail with a parse error.
  39. - **Type**: statement
  40. # file
  41. Return the contents of a file. Multiple files can be passed, and
  42. the first file that exists will be read in.
  43. - **Type**: rvalue
  44. # fqdn\_rand
  45. Generates random numbers based on the node's fqdn. The first
  46. argument sets the range. Additional (optional) arguments may be
  47. used to further distinguish the seed.
  48. - **Type**: rvalue
  49. # generate
  50. Calls an external command on the Puppet master and returns the
  51. results of the command. Any arguments are passed to the external
  52. command as arguments. If the generator does not exit with return
  53. code of 0, the generator is considered to have failed and a parse
  54. error is thrown. Generators can only have file separators,
  55. alphanumerics, dashes, and periods in them. This function will
  56. attempt to protect you from malicious generator calls (e.g., those
  57. with '..' in them), but it can never be entirely safe. No subshell
  58. is used to execute generators, so all shell metacharacters are
  59. passed directly to the generator.
  60. - **Type**: rvalue
  61. # include
  62. Evaluate one or more classes.
  63. - **Type**: statement
  64. # info
  65. Log a message on the server at level info.
  66. - **Type**: statement
  67. # inline\_template
  68. Evaluate a template string and return its value. See
  69. [the templating docs](http://docs.puppetlabs.com/guides/templating.html)
  70. for more information. Note that if multiple template strings are
  71. specified, their output is all concatenated and returned as the
  72. output of the function.
  73. - **Type**: rvalue
  74. # notice
  75. Log a message on the server at level notice.
  76. - **Type**: statement
  77. # realize
  78. Make a virtual object real. This is useful when you want to know
  79. the name of the virtual object and don't want to bother with a full
  80. collection. It is slightly faster than a collection, and, of
  81. course, is a bit shorter. You must pass the object using a
  82. reference; e.g.: `realize User[luke]`.
  83. - **Type**: statement
  84. # regsubst
  85. Perform regexp replacement on a string or array of strings.
  86. - **Parameters** (in order):
  87. target
  88. ~ The string or array of strings to operate on. If an array, the
  89. replacement will be performed on each of the elements in the array,
  90. and the return value will be an array.
  91. regexp
  92. ~ The regular expression matching the target string. If you want
  93. it anchored at the start and or end of the string, you must do that
  94. with \^ and $ yourself.
  95. replacement
  96. ~ Replacement string. Can contain back references to what was
  97. matched using 0, 1, and so on.
  98. flags
  99. ~ Optional. String of single letter flags for how the regexp is
  100. interpreted:
  101. > - **E** Extended regexps
  102. > - **I** Ignore case in regexps
  103. > - **M** Multiline regexps
  104. > - **G** Global replacement; all occurrences of the regexp in each
  105. > target string will be replaced. Without this, only the first
  106. > occurrence will be replaced.
  107. lang
  108. ~ Optional. How to handle multibyte characters. A
  109. single-character string with the following values:
  110. > - **N** None
  111. > - **E** EUC
  112. > - **S** SJIS
  113. > - **U** UTF-8
  114. - **Examples**
  115. Get the third octet from the node's IP address:
  116. $i3 = regsubst($ipaddress,'^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$','\3')
  117. Put angle brackets around each octet in the node's IP address:
  118. $x = regsubst($ipaddress, '([0-9]+)', '<\1>', 'G')
  119. - **Type**: rvalue
  120. # require
  121. Evaluate one or more classes, adding the required class as a
  122. dependency.
  123. The relationship metaparameters work well for specifying
  124. relationships between individual resources, but they can be clumsy
  125. for specifying relationships between classes. This function is a
  126. superset of the 'include' function, adding a class relationship so
  127. that the requiring class depends on the required class.
  128. Warning: using require in place of include can lead to unwanted dependency cycles.
  129. ~ For instance the following manifest, with 'require' instead of
  130. 'include' would produce a nasty dependence cycle, because notify
  131. imposes a before between File[/foo] and Service[foo]:
  132. class myservice {
  133. service { foo: ensure => running }
  134. }
  135. class otherstuff {
  136. include myservice
  137. file { '/foo': notify => Service[foo] }
  138. }
  139. Note that this function only works with clients 0.25 and later, and
  140. it will fail if used with earlier clients.
  141. - **Type**: statement
  142. # search
  143. Add another namespace for this class to search. This allows you to
  144. create classes with sets of definitions and add those classes to
  145. another class's search path.
  146. - **Type**: statement
  147. # sha1
  148. Returns a SHA1 hash value from a provided string.
  149. - **Type**: rvalue
  150. # shellquote
  151. Quote and concatenate arguments for use in Bourne shell.
  152. Each argument is quoted separately, and then all are concatenated
  153. with spaces. If an argument is an array, the elements of that array
  154. is interpolated within the rest of the arguments; this makes it
  155. possible to have an array of arguments and pass that array to
  156. shellquote instead of having to specify each argument individually
  157. in the call.
  158. - **Type**: rvalue
  159. # split
  160. Split a string variable into an array using the specified split
  161. regexp.
  162. Usage:
  163. $string = 'v1.v2:v3.v4'
  164. $array_var1 = split($string, ':')
  165. $array_var2 = split($string, '[.]')
  166. $array_var3 = split($string, '[.:]')
  167. $array\_var1 now holds the result ['v1.v2', 'v3.v4'], while
  168. $array\_var2 holds ['v1', 'v2:v3', 'v4'], and $array\_var3 holds
  169. ['v1', 'v2', 'v3', 'v4'].
  170. Note that in the second example, we split on a string that contains
  171. a regexp meta-character (.), and that needs protection. A simple
  172. way to do that for a single character is to enclose it in square
  173. brackets.
  174. - **Type**: rvalue
  175. # sprintf
  176. Perform printf-style formatting of text.
  177. The first parameter is format string describing how the rest of the
  178. parameters should be formatted. See the documentation for the
  179. `Kernel::sprintf` function in Ruby for all the details.
  180. - **Type**: rvalue
  181. # tag
  182. Add the specified tags to the containing class or definition. All
  183. contained objects will then acquire that tag, also.
  184. - **Type**: statement
  185. # tagged
  186. A boolean function that tells you whether the current container is
  187. tagged with the specified tags. The tags are ANDed, so that all of
  188. the specified tags must be included for the function to return
  189. true.
  190. - **Type**: rvalue
  191. # template
  192. Evaluate a template and return its value. See
  193. [the templating docs](http://docs.puppetlabs.com/guides/templating.html)
  194. for more information. Note that if multiple templates are
  195. specified, their output is all concatenated and returned as the
  196. output of the function.
  197. - **Type**: rvalue
  198. # versioncmp
  199. Compares two versions
  200. Prototype:
  201. $result = versioncmp(a, b)
  202. where a and b are arbitrary version strings
  203. This functions returns a number:
  204. * > 0 if version a is greater than version b
  205. * == 0 if both version are equals
  206. * < 0 if version a is less than version b
  207. Example:
  208. if versioncmp('2.6-1', '2.4.5') > 0 {
  209. notice('2.6-1 is > than 2.4.5')
  210. }
  211. - **Type**: rvalue
  212. # warning
  213. Log a message on the server at level warning.
  214. - **Type**: statement
  215. * * * * *
  216. *This page autogenerated on Mon Jul 19 21:53:31 -0700 2010*