Installing FreeBSD Ports and Packages With CFEngine
Posted by Tres Fri, 07 Jul 2006 12:59:00 GMT
CFEngine has built in functionality to work with RPMS, Debian Packages or Solaris packages, but that doesn’t mean that you can’t use it to manage package installations on FreeBSD.
To manage packages on FreeBSD use group: or class: sections to see whether a package is installed, like this:
groups:
-
has_<package> =( ReturnsZero(/usr/sbin/pkg_info -Eqx <package name>) )
The x flag will treat the package name as a regular expression, so you don’t need to worry about versions – just use the package name that you’re looking for.
Now, once CFEngine knows the state of the package installation, it needs to take action based upon that state. In the shellcommands: section, we’ll tell CFEngine to run the installer if the package state is not installed.
!has_<package>::
-
"/usr/local/sbin/portinstall -y <package name>"
We can use portinstall (part of the portupgrade package) to install packages, or use pkg_add -r install the pre-compiled package.
!has_<package>::
-
"/usr/sbin/pkg_add -r <package name>"
This will automatically take care of installing the package.
Example:
Installing bash via CFEngine
To see whether bash was installed, we would use the following line in the group: or class: section of the .cf file:
groups:
-
has_bash =( ReturnsZero(/usr/sbin/pkg_info -Eqx bash) )
And we’d put the following into the shellcommands: section of the file:
shellcommands:
-
!has_scdp::
-
"/usr/local/sbin/portinstall -y shells/bash"