Promises
One concept in CFEngine should stand out from the rest as being the mostimportant: promises. Everything else is just an abstraction that allows us todeclare promises and model the various actors in the system.
Everything is a promise
Everything in CFEngine 3 can be interpreted as a promise. Promises can be madeabout all kinds of different subjects, from file attributes, to the executionof commands, to access control decisions and knowledge relationships. If youare managing a system that serves web pages you may define a promise that port80 needs to be open on a web server. This same web server may also define apromise that a particular directory has a particular set of permissions andthe proper owner to serve web pages via Apache.
This simple but powerful idea allows a very practical uniformity in CFEnginesyntax.
Promise types
Thepromise_type defines what kind of object is making the promise. The typedictates how CFEngine interprets the promise body. These promise types arestraightforward: Thefiles promise type deals with file permissions and filecontent, and thepackages promise type allows you to work with packagingsystems such as rpm and apt.
Some promise types are common to all CFEngine components, while others canonly be executed by one of them.cf-serverd cannot keeppackages promises,andcf-agent cannot keepaccess promises. See thePromise type reference for a comprehensivelist of promise types.
The promiser
The promiser is an object affected by a promise, and this can be anything: afile, a port on a network. It is the entity that is making a promise that acertain fact will be true. These facts are listed in the form ofattributes andvalues. A file could promise that a permissionattribute has a particular value (i.e. 775 permission value) and that an ownerattribute has another value (i.e. "root").
When a promise is made in CFEngine it is made to another entity - apromisee. A promisee is an optional part of a promise declaration. Thepromisee can help provide insight into the system's configuration, and maybecome relevant as your system grows in complexity.
Theclasses in a promise control the conditions that make the promisevalid. Examples are the operating system on which the policy is executed, orthe day of the week. More about that in theclasses and decisionmaking section.
Not all of these elements are necessary every time, but when you combine themthey enable a wide range of behavior.
Promise example
# Promise typefiles:"/home/mark/tmp/test_plain"->"system blue team",create=>"true",perms=>owner("@(usernames)"),comment=>"Hello World";In this example, the promise is about a file namedtest_plain in thedirectory/home/mark/tmp, and the promise is made to some entity namedsystem blue team. Thecreate attribute instructs CFEngine to create thefile if it doesn't exist. It has a list of owners that is defined by avariable named "usernames" (see the documentation aboutBodies for more details on this lastexpression).
The comment attribute in this example can be added to any promise. It has noactual function other than to provide more information to the user in errortracing and auditing.
This is a promise that will affect the state of a file on the filesystem. InCFEngine you can do this without having to execute thetouch,chmod, andchown commands. CFEngine is declarative: you declare a contract (or apromise) that you want CFEngine to keep and you leave the details up to thetool.
Promise locking
When a promise is validated (has an outcome of kept or repaired) it is lockedforbody agent control ifelapsed minutes (1 by default). Locks are based on ahash of the promise (promiser, associated attributes, and context).
Promise locks can be useful for controlling frequency.
access,classes,defaults,meta,roles andvars type promises do notparticipate in locking.
See also:ifelapsed in body agent control,ifelapsed action body attribute
Promise attributes
Promise attributes have a type and a value. The type can be any of thedatatypes that are allowed for variables, and in addition
Boolean - allowed input values are
"true"/"false""on"/"off""yes"/"no"
irange[min, max]andrrange[min, max]- a range of integer or realvalues, created via theirange()andrrange()functionsclist- a list of classes or class expressions. Note that theseattributes can take both strings (which are evaluated as class expressions)and functions that return typeclassMenu option - one value from a list of values
bodytype - a complex set ofattributes expressed in a separate, reusable blockbundletype - a separate bundlethat is used as a sub-routine or a sub-set of promises
Note: The language does not specifically disallow the use of the sameattribute multiple times within a given promise. As a general rule the lastdefinition wins but the behavior is not clearly defined and this should beavoided.
For example, the following promises use the same attribute multiple times.
bundleagentbad_example{classes:"myclass"expression=>"cfengine",expression=>"my_other_class";files:"/tmp/example"perms=>m(600),perms=>owner("root"),perms=>group("root");}Implicit promises
Some promise types can have implicit behavior. For example, the followingpromise simply prints out a log message "hello world".
reports:"hello world";The same promise could be implemented using thecommands type, invoking theecho command:
commands:"/bin/echo hello world";These two promises have default attributes for everything except thepromiser. Both promises simply cause CFEngine to print a message.
- 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