The context this
is used to access information about promises during their execution. It is context dependent and not universally meaningful or available, but provides a context for variables where one is needed (such as when passing the value of a list variable into a parameterized edit_line
promise from a files
promise).
code
bundle agent resolver(s,n)
{
files:
"$(sys.resolv)"
create => "true",
edit_line => doresolv("@(this.s)","@(this.n)"),
edit_defaults => reconstruct;
}
Note that every unqualified variable is automatically considered to be in context this
, so that a reference to the variable $(foo)
is identical to referencing $(this.foo)
. You are strongly encouraged to not take advantage of this behavior, but simply to be aware that if you attempt to declare a variable name with one of the following special reserved names, CFEngine will issue a warning (and you can reference your variable by qualifying it with the bundle name in which it is declared).
This variable contains the current bundle name.
this.handleThis variable points to the promise handle of the currently handled promise; it is useful for referring to the intention in log messages.
this.namespaceThis variable contains the current namespace name.
this.promise_filenameThis variable reveals the name of the file in which the current promise is defined.
this.promise_dirnameThis variable contains the directory name of the file in which the current promise is defined.
this.promise_linenumberThis variable reveals the line number in the file at which it is used. It is useful to differentiate otherwise identical reports promises.
this.promiserThe special variable $(this.promiser)
is used to refer to the current value of the promiser itself.
In files
promises, where it is practical to use patterns or depth_search
to match multiple objects, the variable refers to the file that is currently making the promise. However, the variable can only be used in selected attributes:
transformer
edit_template
source
in copy_from
exec_program
in file_select
body classes
body action
service_method
For example:
code
bundle agent find666
{
files:
"/home"
file_select => world_writeable,
transformer => "/bin/echo DETECTED $(this.promiser)",
depth_search => recurse("inf");
"/etc/.*"
file_select => world_writeable,
transformer => "/bin/echo DETECTED $(this.promiser)";
}
body file_select world_writeable
{
search_mode => { "o+w" };
file_result => "mode";
}
this.promiser_uid
This variable refers to the uid
(user ID) of the user running the cf-agent
program.
Note: This variable is reported by the platform dependent getuid
function, and is always an integer.
This variable refers to the gid
(group ID) of the user running the cf-agent
program.
Note: This variable is reported by the platform dependent getgid
function, and is always an integer.
This variable refers to the pid
(process ID) of the cf-agent
program.
Note: This variable is reported by the platform dependent getpid
function, and is always an integer.
This variable refers to the ppid
(parent process ID) of the cf-agent
program.
Note: This variable is reported by the platform dependent getpid
function, and is always an integer. On the Windows platform it's always 0.
In a service_method
used by a services
type promise, this variable is set to the value of the service_policy
promise attribute . For example:
code
bundle agent example
{
services:
"www"
service_policy => "start";
service_method => non_standard_services;
}
body service_method non_standard_services
{
service_bundle => non_standard_services( $(this.service_policy) );
}
This is typically used in the adaptations for custom services bundles in the service methods.
See also:
Services Bundles and Bodies
in the Masterfiles Policy Framework standard library
From version 3.3.0 on, this variable is reserved. It is used by functions like maplist()
to represent the current object in a transformation map.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4