lib/common.cf
Seethecommon promise attributesdocumentation for a comprehensive reference on the body types and attributesused here.
action bodies
if_elapsed
Prototype:if_elapsed(x)
Description: Evaluate the promise everyx minutes
Arguments:
x: The time in minutes between promise evaluations
Implementation:
bodyactionif_elapsed(x){ifelapsed=>"$(x)";expireafter=>"$(x)";}if_elapsed_day
Prototype:if_elapsed_day
Description: Evalute the promise once every 24 hours
Implementation:
bodyactionif_elapsed_day{ifelapsed=>"1440";# 60 x 24expireafter=>"1400";}measure_performance
Prototype:measure_performance(x)
Description: Measure repairs of the promiser everyx minutes
Repair-attempts are cancelled afterx minutes.
Arguments:
x: The time in minutes between promise evaluations.
Implementation:
bodyactionmeasure_performance(x){measurement_class=>"Detect changes in$(this.promiser)";ifelapsed=>"$(x)";expireafter=>"$(x)";}measure_promise_time
Prototype:measure_promise_time(identifier)
Description: Performance will be measured and recorded under identifier
Arguments:
identifier: Measurement name.
Implementation:
bodyactionmeasure_promise_time(identifier){measurement_class=>"$(identifier)";}warn_only
Prototype:warn_only
Description: Warn once an hour if the promise needs to be repaired
The promise does not get repaired.
Implementation:
bodyactionwarn_only{action_policy=>"warn";ifelapsed=>"60";}bg
Prototype:bg(elapsed, expire)
Description: Evaluate the promise in the background everyelapsed minutes, for at mostexpire minutes
Arguments:
elapsed: The time in minutes between promise evaluationsexpire: The time in minutes after which a repair-attempt gets cancelled
Implementation:
bodyactionbg(elapsed,expire){ifelapsed=>"$(elapsed)";expireafter=>"$(expire)";background=>"true";}ifwin_bg
Prototype:ifwin_bg
Description: Evaluate the promise in the background when running on Windows
Implementation:
bodyactionifwin_bg{windows::background=>"true";}immediate
Prototype:immediate
Description: Evaluate the promise at everycf-agent execution.
Implementation:
bodyactionimmediate{ifelapsed=>"0";}policy
Prototype:policy(p)
Description: Set theaction_policy top
Arguments:
p: The action policy
Implementation:
bodyactionpolicy(p){action_policy=>"$(p)";}log_repaired
Prototype:log_repaired(log, message)
Description: Logmessage to a filelog=[/file|stdout]
Arguments:
log: The log file for repaired messagesmessage: The log message
Implementation:
bodyactionlog_repaired(log,message){log_string=>"$(sys.date),$(message)";log_repaired=>"$(log)";}log_verbose
Prototype:log_verbose
Description: Sets thelog_level attribute to "verbose"
Implementation:
bodyactionlog_verbose{log_level=>"verbose";}sample_rate
Prototype:sample_rate(x)
Description: Evaluate the promise everyx minutes,A repair-attempt is cancelled after 10 minutes
Arguments:
x: The time in minutes between promise evaluation
Implementation:
bodyactionsample_rate(x){ifelapsed=>"$(x)";expireafter=>"10";}classes bodies
if_repaired
Prototype:if_repaired(x)
Description: Define classx if the promise has been repaired
Arguments:
x: The name of the class
Implementation:
bodyclassesif_repaired(x){promise_repaired=>{"$(x)"};}if_else
Prototype:if_else(yes, no)
Description: Define the classesyes orno depending on promise outcome
Arguments:
yes: The name of the class that should be defined if the promise is kept or repairedno: The name of the class that should be defined if the promise could not be repaired
Implementation:
bodyclassesif_else(yes,no){promise_kept=>{"$(yes)"};promise_repaired=>{"$(yes)"};repair_failed=>{"$(no)"};repair_denied=>{"$(no)"};repair_timeout=>{"$(no)"};}cf2_if_else
Prototype:cf2_if_else(yes, no)
Description: Define the classesyes orno, depending on promise outcome
A version ofif_else that matches CFEngine2 semantics. Neither class is set if the promisedoes not require any repair.
Arguments:
yes: The name of the class that should be defined if the promise is repairedno: The name of the class that should be defined if the promise could not be repaired
Implementation:
bodyclassescf2_if_else(yes,no){promise_repaired=>{"$(yes)"};repair_failed=>{"$(no)"};repair_denied=>{"$(no)"};repair_timeout=>{"$(no)"};}if_notkept
Prototype:if_notkept(x)
Description: Define the classx if the promise is not kept and cannot be repaired.
Arguments:
x: The name of the class that should be defined
Implementation:
bodyclassesif_notkept(x){repair_failed=>{"$(x)"};repair_denied=>{"$(x)"};repair_timeout=>{"$(x)"};}if_ok
Prototype:if_ok(x)
Description: Define the classx if the promise is kept or repaired
Arguments:
x: The name of the class that should be defined
Implementation:
bodyclassesif_ok(x){promise_repaired=>{"$(x)"};promise_kept=>{"$(x)"};}if_ok_cancel
Prototype:if_ok_cancel(x)
Description: Cancel the classx if the promise is kept or repaired
Arguments:
x: The name of the class that should be cancelled
Implementation:
bodyclassesif_ok_cancel(x){cancel_repaired=>{"$(x)"};cancel_kept=>{"$(x)"};}cmd_repair
Prototype:cmd_repair(code, cl)
Description: Define the classcl if an external command in acommands,file orpackagespromise is executed with return codecode
Arguments:
code: The return codes that indicate a successful repaircl: The name of the class that should be defined
See also:repaired_returncodes
Implementation:
bodyclassescmd_repair(code,cl){repaired_returncodes=>{"$(code)"};promise_repaired=>{"$(cl)"};}classes_generic
Prototype:classes_generic(x)
Description: Definex prefixed/suffixed with promise outcome
Arguments:
x: The unique part of the classes to be defined
Implementation:
bodyclassesclasses_generic(x){promise_repaired=>{"promise_repaired_$(x)","$(x)_repaired","$(x)_ok","$(x)_reached"};repair_failed=>{"repair_failed_$(x)","$(x)_failed","$(x)_not_ok","$(x)_error","$(x)_not_kept","$(x)_reached"};repair_denied=>{"repair_denied_$(x)","$(x)_denied","$(x)_not_ok","$(x)_error","$(x)_not_kept","$(x)_reached"};repair_timeout=>{"repair_timeout_$(x)","$(x)_timeout","$(x)_not_ok","$(x)_error","$(x)_not_kept","$(x)_reached"};promise_kept=>{"promise_kept_$(x)","$(x)_kept","$(x)_ok","$(x)_reached"};}results
Prototype:results(scope, class_prefix)
Description: Define classes prefixed withclass_prefix and suffixed withappropriate outcomes: _kept, _repaired, _not_kept, _error, _failed,_denied, _timeout, _reached
Arguments:
scope: The scope in which the class should be defined (bundleornamespace)class_prefix: The prefix for the classes defined
This body can be applied to any promise and sets global(namespace) or local (bundle) classes based on its outcome. Forinstance, withclass_prefix set toabc:
if the promise is to change a file's owner to
nickand the filewas already owned bynick, the classesabc_reachedandabc_keptwill be set.if the promise is to change a file's owner to
nickand the filewas owned byadamand the change succeeded, the classesabc_reachedandabc_repairedwill be set.
This body is a simpler, more consistent version of the bodyscoped_classes_generic, which see. The key difference is thatfewer classes are defined, and only for outcomes that we can know.For example this body does not define "OK/not OK" outcome classes,since a promise can be both kept and failed at the same time.
It's important to understand that promises may do multiple things,so a promise is not simply "OK" or "not OK." The best way tounderstand what will happen when your specific promises get thisbody is to test it in all the possible combinations.
Suffix Notes:
_reachedindicates the promise was tried. Any outcome will resultin a class with this suffix being defined._keptindicates some aspect of the promise was kept_repairedindicates some aspect of the promise was repaired_not_keptindicates some aspect of the promise was not kept.error, failed, denied and timeout outcomes will result in a classwith this suffix being defined_errorindicates the promise repair encountered an error_failedindicates the promise failed_deniedindicates the promise repair was denied_timeoutindicates the promise timed out
Example:
bundleagentexample{commands:"/bin/true"classes=>results("bundle","my_class_prefix");reports:my_class_prefix_kept::"My promise was kept";my_class_prefix_repaired::"My promise was repaired";}See also:scope,scoped_classes_generic,classes_generic
Implementation:
bodyclassesresults(scope,class_prefix){scope=>"$(scope)";promise_kept=>{"$(class_prefix)_reached","$(class_prefix)_kept"};promise_repaired=>{"$(class_prefix)_reached","$(class_prefix)_repaired"};repair_failed=>{"$(class_prefix)_reached","$(class_prefix)_error","$(class_prefix)_not_kept","$(class_prefix)_failed"};repair_denied=>{"$(class_prefix)_reached","$(class_prefix)_error","$(class_prefix)_not_kept","$(class_prefix)_denied"};repair_timeout=>{"$(class_prefix)_reached","$(class_prefix)_error","$(class_prefix)_not_kept","$(class_prefix)_timeout"};}diff_results
Prototype:diff_results(scope, x)
Description: Definex prefixed/suffixed with promise outcome with command return codes adjusted to align withdiff.
Arguments:
scope: The scope the class should be defined with [bundle|namespace].x: The unique part of the classes to be defined.
From man diff:Exit status is 0 if inputs are the same, 1 ifdifferent, 2 if trouble.
Example:
bundleagentexample{commands:"/usr/bin/diff"args=>"/tmp/file1 /tmp/file2",classes=>diff_results("diff");vars:"c"slist=>classesmatching("diff_.*");reports:"Found class '$(c)'";"Files Differ!"if=>"diff_failed|diff_error|diff_not_kept";"Files are the same."if=>"diff_kept";}Implementation:
bodyclassesdiff_results(scope,x){inherit_from=>results($(scope),$(x));kept_returncodes=>{"0"};failed_returncodes=>{"1","2"};}scoped_classes_generic
Prototype:scoped_classes_generic(scope, x)
Description: Definex prefixed/suffixed with promise outcomeSee also:scope
Arguments:
scope: The scope in which the class should be definedx: The unique part of the classes to be defined
Implementation:
bodyclassesscoped_classes_generic(scope,x){scope=>"$(scope)";promise_repaired=>{"promise_repaired_$(x)","$(x)_repaired","$(x)_ok","$(x)_reached"};repair_failed=>{"repair_failed_$(x)","$(x)_failed","$(x)_not_ok","$(x)_error","$(x)_not_kept","$(x)_reached"};repair_denied=>{"repair_denied_$(x)","$(x)_denied","$(x)_not_ok","$(x)_error","$(x)_not_kept","$(x)_reached"};repair_timeout=>{"repair_timeout_$(x)","$(x)_timeout","$(x)_not_ok","$(x)_error","$(x)_not_kept","$(x)_reached"};promise_kept=>{"promise_kept_$(x)","$(x)_kept","$(x)_ok","$(x)_reached"};}state_repaired
Prototype:state_repaired(x)
Description: Definex for 10 minutes if the promise was repaired
Arguments:
x: The name of the class that should be defined
Implementation:
bodyclassesstate_repaired(x){promise_repaired=>{"$(x)"};persist_time=>"10";scope=>"namespace";}enumerate
Prototype:enumerate(x)
Description: Definex for 15 minutes if the promise is either kept or repairedThis is used by commercial editions to count instances of jobs in a cluster
Arguments:
x: The unique part of the class that should be definedThe class defined is prefixed withmXC_
Implementation:
bodyclassesenumerate(x){promise_repaired=>{"mXC_$(x)"};promise_kept=>{"mXC_$(x)"};persist_time=>"15";scope=>"namespace";}always
Prototype:always(x)
Description: Define classx no matter what the outcome of the promise is
Arguments:
x: The name of the class to be defined
Implementation:
bodyclassesalways(x){promise_repaired=>{"$(x)"};promise_kept=>{"$(x)"};repair_failed=>{"$(x)"};repair_denied=>{"$(x)"};repair_timeout=>{"$(x)"};}kept_successful_command
Prototype:kept_successful_command
Description: Set command to "kept" instead of "repaired" if it returns 0
Implementation:
bodyclasseskept_successful_command{kept_returncodes=>{"0"};}- Overview
- Getting started
- Reference
- Components
- Functions
- accessedbefore
- accumulated
- ago
- and
- basename
- bundlesmatching
- bundlestate
- callstack_callers
- callstack_promisers
- canonify
- canonifyuniquely
- cf_version_after
- cf_version_at
- cf_version_before
- cf_version_between
- cf_version_maximum
- cf_version_minimum
- changedbefore
- classesmatching
- classfiltercsv
- classify
- classmatch
- concat
- countclassesmatching
- countlinesmatching
- data_expand
- data_readstringarray
- data_readstringarrayidx
- data_regextract
- data_sysctlvalues
- datastate
- difference
- dirname
- diskfree
- escape
- eval
- every
- execresult
- execresult_as_data
- expandrange
- file_hash
- fileexists
- filesexist
- filesize
- filestat
- filter
- findfiles
- findfiles_up
- findprocesses
- format
- getclassmetatags
- getenv
- getfields
- getgid
- getindices
- getuid
- getuserinfo
- getusers
- getvalues
- getvariablemetatags
- grep
- groupexists
- hash
- hash_to_int
- hashmatch
- host2ip
- hostinnetgroup
- hostrange
- hostsseen
- hostswithclass
- hubknowledge
- ifelse
- int
- intersection
- ip2host
- iprange
- irange
- isdir
- isexecutable
- isgreaterthan
- isipinsubnet
- islessthan
- islink
- isnewerthan
- isplain
- isreadable
- isvariable
- join
- lastnode
- laterthan
- ldaparray
- ldaplist
- ldapvalue
- length
- lsdir
- makerule
- maparray
- mapdata
- maplist
- max
- mean
- mergedata
- min
- network_connections
- none
- not
- now
- nth
- on
- or
- packagesmatching
- packageupdatesmatching
- parseintarray
- parsejson
- parserealarray
- parsestringarray
- parsestringarrayidx
- parseyaml
- peerleader
- peerleaders
- peers
- processexists
- product
- randomint
- read_module_protocol
- readcsv
- readdata
- readenvfile
- readfile
- readintarray
- readintlist
- readjson
- readrealarray
- readreallist
- readstringarray
- readstringarrayidx
- readstringlist
- readtcp
- readyaml
- regarray
- regcmp
- regex_replace
- regextract
- registryvalue
- regldap
- regline
- reglist
- remoteclassesmatching
- remotescalar
- returnszero
- reverse
- rrange
- selectservers
- shuffle
- some
- sort
- splayclass
- splitstring
- storejson
- strcmp
- strftime
- string
- string_downcase
- string_head
- string_length
- string_mustache
- string_replace
- string_reverse
- string_split
- string_tail
- string_trim
- string_upcase
- sublist
- sum
- sysctlvalue
- translatepath
- type
- unique
- url_get
- usemodule
- userexists
- validdata
- validjson
- variablesmatching
- variablesmatching_as_data
- variance
- version_compare
- Language concepts
- Masterfiles Policy Framework
- promises.cf
- .no-distrib/
- update.cf
- standalone_self_upgrade.cf
- cfe_internal/
- cfe_internal/CFE_cfengine.cf
- cfe_internal/core/
- cfe_internal/core/watchdog
- cfe_internal/core/watchdog/watchdog.cf
- cfe_internal/enterprise/
- cfe_internal/enterprise/federation/
- cfe_internal/enterprise/federation/federation.cf
- cfe_internal/recommendations.cf
- cfe_internal/update/
- cfe_internal/update/cfe_internal_dc_workflow.cf
- cfe_internal/update/cfe_internal_update_from_repository.cf
- cfe_internal/update/lib.cf
- cfe_internal/update/systemd_units.cf
- cfe_internal/update/update_bins.cf
- cfe_internal/update/update_policy.cf
- cfe_internal/update/update_processes.cf
- controls/
- controls/cf_agent.cf
- controls/cf_execd.cf
- controls/cf_hub.cf
- controls/cf_monitord.cf
- controls/cf_runagent.cf
- controls/cf_serverd.cf
- controls/def.cf
- controls/def_inputs.cf
- controls/reports.cf
- controls/update_def.cf
- controls/update_def_inputs.cf
- inventory/
- inventory/any.cf
- inventory/debian.cf
- inventory/freebsd.cf
- inventory/generic.cf
- inventory/linux.cf
- inventory/lsb.cf
- inventory/macos.cf
- inventory/os.cf
- inventory/redhat.cf
- inventory/suse.cf
- inventory/windows.cf
- lib/
- lib/autorun.cf
- lib/bundles.cf
- lib/cfe_internal.cf
- lib/cfe_internal_hub.cf
- lib/cfengine_enterprise_hub_ha.cf
- lib/commands.cf
- lib/common.cf
- lib/databases.cf
- lib/edit_xml.cf
- lib/event.cf
- lib/examples.cf
- lib/feature.cf
- lib/files.cf
- lib/guest_environments.cf
- lib/monitor.cf
- lib/packages.cf
- lib/paths.cf
- lib/processes.cf
- lib/reports.cf
- lib/services.cf
- lib/stdlib.cf
- lib/storage.cf
- lib/testing.cf
- lib/users.cf
- lib/vcs.cf
- modules/
- modules/mustache/
- modules/packages/
- modules/packages/vendored/
- modules/promises/
- modules/promises/cfengine.py
- modules/promises/cfengine.sh
- services/
- services/autorun/
- services/main.cf
- Macros
- Promise types
- Special variables
- All promise and body types
- Release notes
- Web UI
- Settings
- Health
- Hosts
- Alerts and notifications
- Custom actions for alerts
- Enterprise reporting
- Federated reporting
- Measurements app
- Hub administration
- Decommissioning hosts
- Extending Mission Portal
- Extending query builder in Mission Portal
- Adjusting schedules
- Backup and restore
- Configure a custom LDAP port
- Custom LDAPs certificate
- Custom SSL certificate
- Enable plain http
- Lookup license info
- Policy deployment
- Public key distribution
- Re-installing Enterprise hub
- Regenerate self signed SSL certificate
- Reset administrative credentials
- Debugging Mission Portal
- License
- Examples and tutorials
- Example snippets
- General examples
- Administration examples
- Measuring examples
- Software administration examples
- Commands, scripts, and execution examples
- File and directory examples
- File template examples
- Interacting with directory services
- Database examples
- Network examples
- System security examples
- System information examples
- System administration examples
- System file examples
- Windows registry examples
- File permissions
- User management examples
- Common promise patterns
- Aborting execution
- Change detection
- Check filesystem space
- Copy single files
- Create files and directories
- Customize message of the day
- Distribute ssh keys
- Ensure a process is not running
- Ensure a service is enabled and running
- Find the MAC address
- Install packages
- Mount NFS filesystem
- Restart a process
- Set up name resolution with DNS
- Set up sudo
- Set up time management through NTP
- Updating from a central policy server
- Tutorials
- JSON and YAML support in CFEngine
- Installing CFEngine Enterprise agent
- Managing local users
- Managing network time protocol
- Managing processes and services
- Package management
- Writing CFEngine policy
- Distributing files from a central location
- File editing
- Reporting and remediation of security vulnerabilities
- Masterfiles Policy Framework upgrade
- Tags for variables, classes, and bundles
- Custom inventory
- Dashboard alerts
- Integrating alerts with PagerDuty
- Integrating alerts with ticketing systems
- Integrating with Sumo Logic
- Rendering files with Mustache templates
- Reporting
- File comparison
- High availability
- Writing and serving policy
- Example snippets
- Resources
- FAQ
- Why knowledge management?
- Requesting a CFEngine Enterprise License
- Uninstalling / reinstalling
- Agent output email
- Debugging slow queries
- Enterprise Report Filtering
- Enterprise report collection
- Enterprise reporting database
- How can I tell what classes and variables are defined?
- How do I find the public key for a given host
- How do I fix trust after an IP change?
- How do I fix undefined body errors?
- How do I integrate custom policy?
- How do I pass a data type variable?
- Manual execution
- Mustache templating
- Unable to log into Mission Portal
- Users
- What is promise locking?
- Why are remote agents not updating?
- Why are some files inside masterfiles not being updated/distributed?
- Why does CFEngine install into /var/cfengine instead of following the FHS?
- Bootstrapping
- Tuning PostgreSQL
- What did CFEngine do?
- External resources
- Additional topics
- Best practices
- FAQ
- API
- Enterprise API examples
- Enterprise API reference
- Actions API
- Build API
- CMDB API
- Changes REST API
- Federated reporting configuration API
- File changes API
- Health diagnostic API
- Host REST API
- Import & export API
- Import & export compliance report API
- Inventory API
- LDAP authentication API
- Personal groups API
- Query REST API
- SQL schema
- SSH keys API
- Shared groups API
- Status and settings REST API
- Two-factor authentication API
- Users and access-control REST API
- VCS settings API
- Web RBAC API