📜  人偶功能

📅  最后修改于: 2021-01-08 05:01:29             🧑  作者: Mango

puppet 功能

众所周知,Puppet使用Ruby编程语言,并且像其他编程语言一样,Ruby也支持函数。我们可以用Ruby语言编写函数,并且可以将其分布在人偶模块中。puppet 提供两种不同类型的功能:

语句:此类函数不返回任何值,而是用于执行独立任务的。它可用于在新清单文件中导入Puppet模块。

rvalue:在Puppet中,如果要使用返回类型定义函数,则可以使用rvalue函数。仅在语句需要值(例如case语句或赋值)时才可以使用rvalue。一个函数只能接受两个参数作为参数。

在Puppet中,我们可以根据需要创建功能。甚至Puppet也提供了许多内置功能。让我们看一些内置函数的列表:

Function Description Syntax Type
abs It will return the absolute value of a Numeric value. abs(Numeric($str_val)) rvalue
alert This function is used for logging a message on the server at level alert. alert(Any *$values) statement
break Breaks an innermost iteration as if an end of input was found. This function doesn’t accept any argument. break() statement
binary_file This function loads a binary file from a module or file system and returns binary content. binary_file(String $path) rvalue
call Used to call an arbitrary function by name. call(String $function_name, Any *$arguments, Optional[Callable] &$block) statement
create_resources This function is used to change a hash into a collection of resources and inserts them into the catalog. create_resources($type, $resources) statement
debug Logs a message on the server at level debug. debug(Any *$values) statement
crit Logs a message on the server at the level crit. crit(Any *$values) statement
defined Verify whether a given class or resource type is defined. defined(Variant[String, Type[CatalogEntry], Type[Type[CatalogEntry]]] *$vals) rvalue
emerg This function is used for logging a message on the server at level emerg. emerg(Any *$values) statement
fail Fail with a parser error. fail() statement
err This function is used for logging a message on the server at level err. err(Any *$values) statement
file It takes a file from a module and returns its contents as a string. file() rvalue
fqdn_rand Used to generate random numbers based on the fqdn of the node. fqdn_rand(MAX, [SEED]) rvalue
include This is used to evaluate one or more classes. include(Any *$names) statement
info This function is used for logging a message on the server at level info. info(Any *$values) statement
inline_template This is used to evaluate a template string and return its value. inline_template() rvalue
join This function is used to join an array of values into a string with elements separated by a delimiter. join(Array $arg, Optional[String] $delimiter) rvalue
keys This function is used to return the keys of a hash as an Array. keys(Hash $hsh) rvalue
md5 This function is used to return an MD5 hash value from a given string. md5() rvalue
new This function creates a new instance of an object of a specified data type. new(Type $type, Any *$args, Optional[Callable] &$block) statement
notice This function is used for logging a message on the server at level notice. notice(Any *$values) statement
realize This is used to make a virtual object real. realize() statement
require This is used to evaluate one or more classes and adding the required class as a dependency. require(Any *$names) statement
round This is used to return an Integer value rounded to the nearest value. round(Numeric $val) rvalue
rstrip Strips trailing spaces from a String rstrip(String $arg) rvalue
sha1 This is used to return a SHA1 hash value from a given string. sha1() rvalue
sha256 This function is used to Return a SHA256 hash value from a given string. sha256() rvalue
shellquote This function is used to quote and concatenate arguments for use in Bourne shell. shellquote() rvalue
size Used to return the size of String, Hash, Array, or Binary value. size(Variant[Collection, String, Binary] $arg) rvalue
length Used to return the length of String, Hash, Array, or Binary value. length(Variant[Collection, String, Binary] $arg) rvalue
split Splits a string into an array using a given pattern. split(String $str, String $pattern) rvalue
sprintf This function does printf-style formatting of text. sprintf() rvalue
strip Strips leading and trailing spaces from a String strip(Iterable[Variant[String, Numeric]] $arg) rvalue
tag This function is used to add the given tags to the containing class or to the definition. tag() statement
tagged This function is used to test whether the latest container is tagged with the given tags or not. It will return the Boolean value. tagged() rvalue
template This function first loads an ERB template from the module and then evaluates the output value as a string.  template() rvalue
upcase This function is used to convert a String, Array, or Hash (recursively) into the upper case. upcase(String $arg) rvalue
values This function is used to return the values of a hash as an Array. values(Hash $hsh) rvalue
versioncmp This function is used to compare two version numbers. versioncmp(String $a, String $b) rvalue
warning This function is used for logging a message on the server at the warning level. warning(Any *$values) statement