Namespaces
By default all promises are made in thedefault namespace. Specifying a namespaceplaces the bundle or body in a different namespace to allow re-use of commonnames. Using namespaces makes it easier to share and consume policy from otherauthors.
Like bundle names and classes, namespaces may only contain alphanumeric andunderscore characters (a-zA-Z0-9_).
Declaration
Namespaces are declared withbody file control. Anamespace applies within a single file to all subsequently defined bodies and bundlesfollowing the namespace declaration until a different namespace has beendeclared or until the end of the file.
bundleagent__main__{methods:"Main in my_namespace namespace"usebundle=>my_namespace:main;"Main in your_namespace namespace"usebundle=>your_namespace:main;"my_bundle in default namespace"usebundle=>my_bundle;reports:"Inside$(this.namespace):$(this.bundle)";}bodyfilecontrol{namespace=>"my_namespace";}bundleagentmain{reports:"Inside$(this.namespace):$(this.bundle)";}bodyfilecontrol{namespace=>"your_namespace";}bundleagentmain{reports:"Inside$(this.namespace):$(this.bundle)";}bodyfilecontrol{namespace=>"default";}bundleagentmy_bundle{reports:"Inside$(this.namespace):$(this.bundle)";}R: Inside my_namespace:mainR: Inside your_namespace:mainR: Inside default:my_bundleR: Inside default:mainThis policy can be found in/var/cfengine/share/doc/examples/namespace_declaration.cfand downloaded directly fromgithub.
Notes:
- Multiple namespaces can be declared within the same file
- The same namespace can be declared in multiple files
- The same namespace can be declared in the same file multiple times
Methods|usebundle
Methods promises assume you are referring to a bundle in the same namespace asthe promiser. To refer to a bundle in another namespace youmust specify thenamespace by prefixing the bundle name with the namespace followed by a colon(:).
bundleagent__main__{methods:# Call the bundle named main within the example_space namespace."example_space:main";}bodyfilecontrol{namespace=>"example_space";}bundleagentmain{methods:# Call the bundle 'my_bundle' within the current namespace"When not specified, we assume you are refering to a bundle or body within the same namespace"usebundle=>my_bundle("Called 'my_bundle' from$(this.namespace):$(this.bundle) (the same namespace).");# Call the bundle 'my_bundle' from the 'example_space' namespace"When explicitly specified, the policy reader has less congnitive burden"usebundle=>example_space:my_bundle("Called 'example_space:my_bundle'$(this.namespace):$(this.bundle) (the same namespace).");}bundleagentmy_bundle(string){reports:"In$(this.namespace):$(this.bundle)"handle=>"$(string)";"$(string)";}R: In example_space:my_bundleR: Called 'my_bundle' from example_space:main (the same namespace).R: In example_space:my_bundleR: Called 'example_space:my_bundle' example_space:main (the same namespace).This policy can be found in/var/cfengine/share/doc/examples/namespace_methods-usebundle.cfand downloaded directly fromgithub.
Bodies
Bodies are assumed to be within the same namespace as the promiser. To use a body from another namespace the namespace must be specified by prefixing the body name with the namespace followed by a colon (:).
A common mistake is forgetting to specifydefault: when using bodies from the standard library which resides in thedefault namespace.
bundleagent__main__{methods:"example_space:main";}bodyfilecontrol{namespace=>"example_space";}bundleagentmain{reports:# Use the 'first_line' printfile body from the current namespace"Specifying a body without explict namespace assumes the same namespace.$(const.n)Show me the first 1 line of this file"printfile=>first_line($(this.promise_filename));# Use the 'first_two_lines' printfile body from the 'default' namespace"Forgetting to prefix bodies with 'default:' is a common mistake when using the standard library.$(const.n)Show me the first 2 line of this file"printfile=>default:first_two_lines($(this.promise_filename));}bodyprintfilefirst_line(file){file_to_print=>"$(file)";number_of_lines=>"1";}bodyfilecontrol{namespace=>"default";}bodyprintfilefirst_two_lines(file){file_to_print=>"$(file)";number_of_lines=>"2";}R: Specifying a body without explict namespace assumes the same namespace.Show me the first 1 line of this fileR: bundle agent __main__R: Forgetting to prefix bodies with 'default:' is a common mistake when using the standard library.Show me the first 2 line of this fileR: bundle agent __main__R: {This policy can be found in/var/cfengine/share/doc/examples/namespace_bodies.cfand downloaded directly fromgithub.
Variables
Variables (except forSpecial variables) are assumed to be within the same scopeas the promiser but can also be referenced fully qualified with the namespace.
bundleagent__main__{methods:"example:demo";}bodyfilecontrol{namespace=>"example";}bundleagentdemo{vars:"color"string=>"#f5821f";reports:"Unqualified: The color is$(color)";# ENT-8817 "Bundle-qualified: The color is $(demo.color)";"Fully-qualified: The color is$(example:demo.color)";}R: Unqualified: The color is #f5821fR: Fully-qualified: The color is #f5821fThis policy can be found in/var/cfengine/share/doc/examples/namespace_variable_references.cfand downloaded directly fromgithub.
Special variables are always accessible without a namespace prefix. For example,this,mon,sys, andconst fall in this category.
bundleagent__main__{methods:"special_variables_example:demo";}bodyfilecontrol{namespace=>"special_variables_example";}bundleagentdemo{reports:"Special Variables live in the default namespace but don't have to be fully qualified when referenced ...";"In$(this.namespace):$(this.bundle)$(const.dollar)(sys.cf_version_major) ==$(sys.cf_version_major)";"In$(this.namespace):$(this.bundle)$(default:const.dollar)(default:sys.cf_version_major) ==$(default:sys.cf_version_major)";}R: Special Variables live in the default namespace but don't have to be fully qualified when referenced ...R: In special_variables_example:demo $(sys.cf_version_major) == 3R: In special_variables_example:demo $(default:sys.cf_version_major) == 3This policy can be found in/var/cfengine/share/doc/examples/namespace_special_var_exception.cfand downloaded directly fromgithub.
Notes:
- The
variablesAugments key defines variables in themainbundle of thedatanamespace by default but supports seeding variablevalues in any specified namespace.
Classes
Promises can only define classes within the current namespace. Classes areunderstood to refer to classes in the current namespace if a namespace is notspecified (except for Hard classes). To refer to aclass in a different namespace prefix the class with the namespace suffixed by acolon (:).
bundleagent__main__{methods:"mynamespace:my_bundle";reports:a_bundle_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I see 'a_bundle_scoped_class_in_my_namespaced_bundle::'";!a_bundle_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I do not see 'a_bundle_scoped_class_in_my_namespaced_bundle::'";a_namespace_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I see 'a_namespace_scoped_class_in_my_namespaced_bundle::'";!a_namespace_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I do not see 'a_namespace_scoped_class_in_my_namespaced_bundle::'";mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I see 'mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::'";!mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I do not see 'mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::'";mynamespace:a_namespace_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I see 'mynamespace:a_namespace_scoped_class_in_my_namespaced_bundle::'";}bodyfilecontrol{namespace=>"mynamespace";}bundleagentmy_bundle{classes:"a_bundle_scoped_class_in_my_namespaced_bundle";"a_namespace_scoped_class_in_my_namespaced_bundle"scope=>"namespace";reports:a_bundle_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I see 'a_bundle_scoped_class_in_my_namespaced_bundle::'";!a_bundle_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I do not see 'a_bundle_scoped_class_in_my_namespaced_bundle::'";a_namespace_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I see 'a_namespace_scoped_class_in_my_namespaced_bundle::'";!a_namespace_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I do not see 'a_namespace_scoped_class_in_my_namespaced_bundle::'";mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I see 'mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::'";!mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I do not see 'mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::'";mynamespace:a_namespace_scoped_class_in_my_namespaced_bundle::"In$(this.namespace):$(this.bundle) I see 'mynamespace:a_namespace_scoped_class_in_my_namespaced_bundle::'";}R: In mynamespace:my_bundle I see 'a_bundle_scoped_class_in_my_namespaced_bundle::'R: In mynamespace:my_bundle I see 'a_namespace_scoped_class_in_my_namespaced_bundle::'R: In mynamespace:my_bundle I see 'mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::'R: In mynamespace:my_bundle I see 'mynamespace:a_namespace_scoped_class_in_my_namespaced_bundle::'R: In default:main I do not see 'a_bundle_scoped_class_in_my_namespaced_bundle::'R: In default:main I do not see 'a_namespace_scoped_class_in_my_namespaced_bundle::'R: In default:main I do not see 'mynamespace:a_bundle_scoped_class_in_my_namespaced_bundle::'R: In default:main I see 'mynamespace:a_namespace_scoped_class_in_my_namespaced_bundle::'This policy can be found in/var/cfengine/share/doc/examples/namespace_classes.cfand downloaded directly fromgithub.
Hard classes exist in all namespaces andthus can be referred to from any namespace without qualification.
bundleagent__main__{methods:"example:my_bundle";reports:cfengine::"From the '$(this.namespace)' namespace the class expression 'cfengine::' evaluates true";default:cfengine::"From the '$(this.namespace)' namespace the class expression 'default:cfengine::' evaluates true";"The class 'cfengine' has tags:$(with)"with=>join(", ",getclassmetatags("cfengine"));}bodyfilecontrol{namespace=>"example";}bundleagentmy_bundle{reports:cfengine::"From the '$(this.namespace)' namespace the class expression 'cfengine::' evaluates true";default:cfengine::"From the '$(this.namespace)' namespace the class expression 'default:cfengine::' evaluates true";}R: From the 'example' namespace the class expression 'cfengine::' evaluates trueR: From the 'example' namespace the class expression 'default:cfengine::' evaluates trueR: From the 'default' namespace the class expression 'cfengine::' evaluates trueR: From the 'default' namespace the class expression 'default:cfengine::' evaluates trueR: The class 'cfengine' has tags: inventory, attribute_name=none, source=agent, hardclassThis policy can be found in/var/cfengine/share/doc/examples/namespace_hard_classes.cfand downloaded directly fromgithub.
- 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