Software administration examples
- Software and patch installation
- Postfix mail configuration
- Set up a web server
- Add software packages to the system
- Application baseline
- Service management (windows)
- Software distribution
- Web server modules
- Ensure a service is enabled and running
- Managing Software
- Install packages
Software and patch installation
Example for Debian:
bodycommoncontrol{bundlesequence=>{"packages"};}bodyagentcontrol{environment=>{"DEBIAN_FRONTEND=noninteractive"};}bundleagentpackages{vars:# Test the simplest case -- leave everything to the yum smart manager"match_package"slist=>{"apache2"# "apache2-mod_php5",# "apache2-prefork",# "php5"};packages:"$(match_package)"package_policy=>"add",package_method=>apt;}bodypackage_methodapt{any::# ii acpi 0.09-3ubuntu1package_changes=>"bulk";package_list_command=>"/usr/bin/dpkg -l";package_list_name_regex=>"ii\s+([^\s]+).*";package_list_version_regex=>"ii\s+[^\s]+\s+([^\s]+).*";# package_list_arch_regex => "none";package_installed_regex=>".*";# all reported are installed#package_name_convention => "$(name)_$(version)_$(arch)";package_name_convention=>"$(name)";# Use these only if not using a separate version/arch string# package_version_regex => "";# package_name_regex => "";# package_arch_regex => "";package_add_command=>"/usr/bin/apt-get --yes install";package_delete_command=>"/usr/bin/apt-get --yes remove";package_update_command=>"/usr/bin/apt-get --yes dist-upgrade";#package_verify_command => "/bin/rpm -V";}Examples MSI for Windows, by name:
bodycommoncontrol{bundlesequence=>{"packages"};}bundleagentpackages{vars:"match_package"slist=>{"7zip"};packages:"$(match_package)"package_policy=>"update",package_select=>">=",package_architectures=>{"x86_64"},package_version=>"3.00",package_method=>msi_vmatch;}bodypackage_methodmsi_vmatch{package_changes=>"individual";package_file_repositories=>{"$(sys.workdir)\software_updates\windows","s:\su"};package_installed_regex=>".*";package_name_convention=>"$(name)-$(version)-$(arch).msi";package_add_command=>"\"$(sys.winsysdir)\msiexec.exe\" /qn /i";package_update_command=>"\"$(sys.winsysdir)\msiexec.exe\" /qn /i";package_delete_command=>"\"$(sys.winsysdir)\msiexec.exe\" /qn /x";}Windows MSI by version:
bodycommoncontrol{bundlesequence=>{"packages"};}bundleagentpackages{vars:"match_package"slist=>{"7zip"};packages:"$(match_package)"package_policy=>"update",package_select=>">=",package_architectures=>{"x86_64"},package_version=>"3.00",package_method=>msi_vmatch;}bodypackage_methodmsi_vmatch{package_changes=>"individual";package_file_repositories=>{"$(sys.workdir)\software_updates\windows","s:\su"};package_installed_regex=>".*";package_name_convention=>"$(name)-$(version)-$(arch).msi";package_add_command=>"\"$(sys.winsysdir)\msiexec.exe\" /qn /i";package_update_command=>"\"$(sys.winsysdir)\msiexec.exe\" /qn /i";package_delete_command=>"\"$(sys.winsysdir)\msiexec.exe\" /qn /x";}Examples for solaris:
bundleagentexample_using_ips_package_method{packages:solaris::"shell/zsh"package_policy=>"add",package_method=>ips;}bundleagentexample_using_solaris_package_method{files:solaris::"/tmp/$(admin_file)"create=>"true",edit_defaults=>empty_file,# defined in stdlibedit_line=>create_solaris_admin_file;# defined in stdlibpackages:solaris::"SMCzlib"package_policy=>"add",package_method=>solaris("SMCzlib","zlib-1.2.3-sol10-sparc-local","$(admin_file)");}bundleagentexample_using_solaris_install_package_method{packages:solaris::"SMCzlib"package_method=>solaris_install("/tmp/SMCzlib.adminfile")}bundleagentexample_using_pkgsrc_module{packages:solaris::"vim"policy=>"present",package_module=>pkgsrc;}Examples for yum based systems:
bodycommoncontrol{bundlesequence=>{"packages"};inputs=>{"cfengine_stdlib.cf"};}bundleagentpackages{vars:# Test the simplest case -- leave everything to the yum smart manager"match_package"slist=>{"apache2","apache2-mod_php5","apache2-prefork","php5"};packages:"$(match_package)"package_policy=>"add",package_method=>yum;}SuSE Linux's package manager zypper is the most powerful alternative:
bodycommoncontrol{bundlesequence=>{"packages"};inputs=>{"cfengine_stdlib.cf"}}bundleagentpackages{vars:# Test the simplest case -- leave everything to the zypper smart manager"match_package"slist=>{"apache2","apache2-mod_php5","apache2-prefork","php5"};packages:"$(match_package)"package_policy=>"add",package_method=>zypper;}Postfix mail configuration
bodycommoncontrol{inputs=>{"$(sys.libdir)/stdlib.cf"};bundlesequence=>{postfix};}bundleagentpostfix{vars:"prefix"string=>"/etc";"smtpserver"string=>"localhost";"mailrelay"string=>"mailx.example.org";files:"$(prefix)/main.cf"edit_line=>prefix_postfix;"$(prefix)/sasl-passwd"create=>"true",perms=>mo("0600","root"),edit_line=>append_if_no_line("$(smtpserver) _$(sys.fqhost):chmsxrcynz4etfrejizhs22");}bundleedit_lineprefix_postfix{## Value have the form NAME = "quoted space separated list"#vars:"ps[relayhost]"string=>"[$(postfix.mailrelay)]:587";"ps[mydomain]"string=>"iu.hio.no";"ps[smtp_sasl_auth_enable]"string=>"yes";"ps[smtp_sasl_password_maps]"string=>"hash:/etc/postfix/sasl-passwd";"ps[smtp_sasl_security_options]"string=>"";"ps[smtp_use_tls]"string=>"yes";"ps[default_privs]"string=>"mailman";"ps[inet_protocols]"string=>"all";"ps[inet_interfaces]"string=>"127.0.0.1";"parameter_name"slist=>getindices("ps");delete_lines:"$(parameter_name).*";insert_lines:"$(parameter_name) =$(ps[$(parameter_name)])";}bundleedit_lineAppendIfNSL(parameter){insert_lines:"$(parameter)";# This is default}Set up a web server
Adapt this template to your operating system by adding multiple classes. Each web server runs something like the present module, which is entered into the bundlesequence like this:
bundleagentweb_server(state){vars:"document_root"string=>"/";##################################################### Site specific configuration - put it in this file####################################################"site_http_conf"string=>"/home/mark/CFEngine-inputs/httpd.conf";##################################################### Software base####################################################"match_package"slist=>{"apache2","apache2-mod_php5","apache2-prefork","php5"};#########################################################processes:web_ok.on::"apache2"restart_class=>"start_apache";off::"apache2"process_stop=>"/etc/init.d/apache2 stop";#########################################################commands:start_apache::"/etc/init.d/apache2 start";# or startssl#########################################################packages:"$(match_package)"package_policy=>"add",package_method=>zypper,classes=>if_ok("software_ok");#########################################################files:software_ok::"/etc/sysconfig/apache2"edit_line=>fixapache,classes=>if_ok("web_ok");#########################################################reports:!software_ok.on::"The web server software could not be installed";#########################################################classes:"on"expression=>strcmp("$(state)","on");"off"expression=>strcmp("$(state)","off");}bundleedit_linefixapache{vars:"add_modules"slist=>{"ssl","php5"};"del_modules"slist=>{"php3","php4","jk"};insert_lines:"APACHE_CONF_INCLUDE_FILES=\"$(web_server.site_http_conf)\"";field_edits:###################################################################### APACHE_MODULES="actions alias ssl php5 dav_svn authz_default jk" etc..#####################################################################"APACHE_MODULES=.*"# Insert module "columns" between the quoted RHS# using space separatorsedit_field=>quotedvar("$(add_modules)","append");"APACHE_MODULES=.*"# Delete module "columns" between the quoted RHS# using space separatorsedit_field=>quotedvar("$(del_modules)","delete");# if this line already exists, edit it}Add software packages to the system
bodycommoncontrol{inputs=>{"$(sys.libdir)/packages.cf"}bundlesequence=>{"packages"};}bundleagentpackages{vars:"match_package"slist=>{"apache2","apache2-mod_php5","apache2-prefork","php5"};packages:solaris::"$(match_package)"package_policy=>"add",package_method=>solaris;redhat|SuSE::"$(match_package)"package_policy=>"add",package_method=>yum_rpm;methods:# equivalent in 3.6, no OS choices""usebundle=>ensure_present($(match_package));}Note you can also arrange to hide all the differences between package managers on an OS basis, but since some OSs have multiple managers, this might not be 100 percent correct.
Application baseline
bundleagentapp_baseline{methods:windows::"any"usebundle=>detect_adobereader;}bundleagentdetect_adobereader{vars:windows::"value1"string=>registryvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\9.0\Installer","ENU_GUID");"value2"string=>registryvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\9.0\Installer","VersionMax");"value3"string=>registryvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\9.0\Installer","VersionMin");classes:windows::"is_correct"and=>{strcmp($(value1),"{AC76BA86-7AD7-1033-7B44-A93000000001}"),strcmp($(value2),"90003"),islessthan($(value3),"10001")};reports:windows.!is_correct::'AdobeReaderisnotcorrectlydeployed-got"$(value1)","$(value2)","$(value3)"';}Service management (windows)
bodycommoncontrol{bundlesequence=>{"winservice"};}bundleagentwinservice{vars:"bad_services"slist=>{"Alerter","ClipSrv"};services:windows::"$(bad_services)"service_policy=>"disable",comment=>"Disable services that create security issues";}Software distribution
bundleagentcheck_software{vars:# software to install if not installed"include_software"slist=>{"7-zip-4.50-$(sys.arch).msi"};# this software gets updated if it is installed"autoupdate_software"slist=>{"7-zip"};# software to uninstall if it is installed"exclude_software"slist=>{"7-zip-4.65-$(sys.arch).msi"};methods:# "any" usebundle => add_software( "@(check_software.include_software)", "$(sys.policy_hub)" );# "any" usebundle => update_software( "@(check_software.autoupdate_software)", "$(sys.policy_hub)" );# "any" usebundle => remove_software( "@(check_software.exclude_software)", "$(sys.policy_hub)" );}bundleagentadd_software(pkg_name){vars:# dir to install from locally - can also check multiple directories"local_software_dir"string=>"C:\Program Files\Cfengine\software\add";files:"$(local_software_dir)"copy_from=>remote_cp("/var/cfengine/master_software_updates/$(sys.flavour)_$(sys.arch)/add","$(srv)"),depth_search=>recurse("1"),classes=>if_repaired("got_newpkg"),comment=>"Copy software from remote repository";packages:# When to check if the package is installed ?got_newpkg|any::"$(pkg_name)"package_policy=>"add",package_method=>msi_implicit("$(local_software_dir)"),classes=>if_else("add_success","add_fail"),comment=>"Install new software, if not already present";reports::add_fail::"Failed to install one or more packages";}#########################################################################bundleagentupdate_software(sw_names){vars:# dir to install from locally - can also check multiple directories"local_software_dir"string=>"C:\Program Files\Cfengine\software\update";files:"$(local_software_dir)"copy_from=>remote_cp("/var/cfengine/master_software_updates/$(sys.flavour)_$(sys.arch)/update","$(srv)"),depth_search=>recurse("1"),classes=>if_repaired("got_newpkg"),comment=>"Copy software updates from remote repository";packages:# When to check if the package is updated ?got_newpkg|any::"$(sw_names)"package_policy=>"update",package_select=>">=",# picks the newest update availablepackage_architectures=>{"$(sys.arch)"},# install 32 or 64 bit package ?package_version=>"1.0",# at least version 1.0package_method=>msi_explicit("$(local_software_dir)"),classes=>if_else("update_success","update_fail");reports:update_fail::"Failed to update one or more packages";}#########################################################################bundleagentremove_software(pkg_name){vars:# dir to install from locally - can also check multiple directories"local_software_dir"string=>"C:\Program Files\Cfengine\software\remove";files:"$(local_software_dir)"copy_from=>remote_cp("/var/cfengine/master_software_updates/$(sys.flavour)_$(sys.arch)/remove","$(srv)"),depth_search=>recurse("1"),classes=>if_repaired("got_newpkg"),comment=>"Copy removable software from remote repository";packages:got_newpkg::"$(pkg_name)"package_policy=>"delete",package_method=>msi_implicit("$(local_software_dir)"),classes=>if_else("remove_success","remove_fail"),comment=>"Remove software, if present";reports::remove_fail::"Failed to remove one or more packages";}Web server modules
The problem of editing the correct modules into the list of standard modules for the Apache web server. This example is based on the standard configuration deployment of SuSE Linux. Simply provide the list of modules you want and another list that you don't want.
bodycommoncontrol{inputs=>{"$(sys.libdir)/stdlib.cf"};bundlesequence=>{apache};}bundleagentapache{files:SuSE::"/etc/sysconfig/apache2"edit_line=>fixapache;}bundleedit_linefixapache{vars:"add_modules"slist=>{"dav","dav_fs","ssl","php5","dav_svn","xyz","superduper"};"del_modules"slist=>{"php3","jk","userdir","imagemap","alias"};insert_lines:"APACHE_CONF_INCLUDE_FILES=\"/site/masterfiles/local-http.conf\"";field_edits:###################################################################### APACHE_MODULES="authz_host actions alias ..."###################################################################### Values have the form NAME = "quoted space separated list""APACHE_MODULES=.*"# Insert module "columns" between the quoted RHS# using space separatorsedit_field=>quoted_var($(add_modules),"append");"APACHE_MODULES=.*"# Delete module "columns" between the quoted RHS# using space separatorsedit_field=>quoted_var($(del_modules),"delete");# if this line already exists, edit it}- 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