CFEngine documentation homepage
  • Product
  • Blog
  • Docs versions
    Version
    master 3.21 (LTS) 3.18 (LTS) view all versions
  • Try for free
  • Examples and Tutorials
  • /
  • Example Snippets

Example Snippets

Suggest changes
Table of contents
  • General Examples
  • Administration Examples
  • Measuring Examples
  • Software Administration Examples
  • Commands, Scripts, and Execution Examples
  • File and Directory Examples
  • File Template Examples
  • Database Examples
  • Network Examples
  • System Security Examples
  • System Information Examples
  • System Administration Examples
  • System File Examples
  • Windows Registry Examples
  • User Management
  • examples
  • policy
  • example snippets

Still need help?

Chat Ask a question on Github Mailing list
Version 
master 3.21 (LTS) 3.18 (LTS) view all versions
    • Overview
      • What is CFEngine and Why?
      • How CFEngine works
      • CFEngine Directory Structure
      • Client server communication
      • Glossary
    • Getting Started
      • Installation
        • Pre-Installation Checklist
          • Quick-Start Guide to Using vi
          • Quick-Start Guide to Using PuTTY
          • Verifying package signatures
        • Local virtual machine
        • General Installation
          • Using Amazon Web Services
          • Installing Enterprise 25 Free
          • Using Vagrant
          • Installing Enterprise for Production
          • Installing Enterprise on CoreOS
          • Installing Community
          • Installing from Binary tarball
        • Secure Bootstrap
        • Installation overview
        • Upgrading
        • Version Control
      • Modules from CFEngine Build
      • Reporting and Web UI
      • Writing policy
      • Developing modules
    • Release Notes
      • New in CFEngine
        • ChangeLog
        • Masterfiles ChangeLog
        • Enterprise ChangeLog
      • Supported Platforms and Versions
      • Known Issues
    • Web UI
      • Settings
      • Health
      • Hosts
      • Alerts and Notifications
      • Custom actions for Alerts
      • Enterprise Reporting
        • Reporting Architecture
        • SQL Queries Using the Enterprise API
        • Reporting UI
        • Client Initiated Reporting / Call collect
      • 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
    • API
      • Enterprise API Examples
        • Checking Status
        • Managing Settings
        • Managing Users and Roles
        • Browsing Host Information
        • Tracking changes
        • SQL Query 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
        • Query REST API
        • SQL Schema
        • SSH keys API
        • Status and Settings REST API
        • Users and Access-Control REST API
        • VCS settings API
        • Web RBAC API
    • Examples and Tutorials
      • Example Snippets
        • General Examples
        • Administration 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
        • 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
      • Tutorials
        • JSON and YAML Support in CFEngine
        • Installing CFEngine Enterprise Agent
        • Manage Network Time Protocol
        • Manage local users
        • Manage packages
        • Manage processes and services
        • Write CFEngine policy
        • Create, Modify, and Delete Files
        • Distribute files from a central location
        • 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
        • Render files with Mustache templates
        • Reporting
          • Monitoring and Reporting
          • Command-Line Reports
        • File Comparison
        • High Availability
          • Installation Guide
        • Writing and Serving Policy
          • Layers of Abstraction in Policy
          • Promises Available in CFEngine
          • Authoring Policy Tools & Workflow
          • Editors
          • Policy Style Guide
          • Bundles Best Practices
          • External Data
          • Testing Policies
          • Controlling Frequency
    • Reference
      • Components
        • cf-agent
        • cf-secret
        • cf-support
        • cf-serverd
        • cf-execd
        • cf-promises
        • cf-monitord
        • cf-key
        • cf-runagent
        • cf-check
        • cf-hub
        • cf-net
        • cf-reactor
        • file control
      • Promise Types
        • access
        • classes
        • commands
        • custom
        • defaults
        • files
          • edit_line
            • delete_lines
            • field_edits
            • insert_lines
            • replace_patterns
          • edit_xml
            • build_xpath
            • delete_attribute
            • delete_text
            • delete_tree
            • insert_text
            • insert_tree
            • set_attribute
            • set_text
        • measurements
        • meta
        • methods
        • packages
        • packages (deprecated)
        • processes
        • reports
        • roles
        • services
        • storage
        • users
        • vars
        • databases
        • guest_environments
      • 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
        • 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
      • Language Concepts
        • Bundles
        • Bodies
        • Promises
        • Normal Ordering
        • Classes and Decisions
        • Variables
        • Augments
        • Loops
        • Pattern Matching and Referencing
        • Modules
          • Package Modules
        • Namespaces
      • Special Variables
        • connection
        • const
        • def
        • edit
        • match
        • mon
        • sys
        • this
      • 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/packages/
        • modules/packages/vendored/
        • modules/promises/
        • modules/promises/cfengine.py
        • modules/promises/cfengine.sh
        • services/
        • services/autorun/
        • services/main.cf
      • Macros
      • All Promise and Body Types
    • Resources
      • FAQ
        • Why knowledge management?
        • Requesting a CFEngine Enterprise License
        • Uninstalling/Reinstalling
        • Agent output email
        • Debugging Slow Queries
        • Enterprise Report Filtering
        • Enterprise Reporting database
        • Enterprise report collection
        • 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?
      • Additional topics
        • Agility
        • Application Management
        • Build Deploy Manage Audit
        • Change Management
        • Cloud Computing
        • Content Driven Policy
        • Devops
        • Distributed Scheduling
        • File Content
        • Glossary
        • Hierarchies
        • ITIL
        • Iteration (Loops)
        • Modularity and Orchestrating System Policy
        • Orchestration
        • STIGs
        • Security
        • Teamwork
        • Using CFEngine with Open Nebula
      • External resources
      • Best Practices
    • CFEngine homepage
    • Download all documentation
    • Legal and Licenses
    • Contact us
    • Last update on 26 January 2023