CFEngine - set variable if a specific package version is installed

210 Views Asked by At

A script needs to support two servers, Fedora and Centos, with different versions of httpd (Apache). CFEngine is used to create the configuration file and it needs to put different sections to the file depending on which httpd version is installed in the system. How can I set a variable to true/false depending on which version is installed so that I can then generate the file appropriately? All the examples I could find only deal with installing, upgrading or removing packages.

2

There are 2 best solutions below

5
On BEST ANSWER

You could use packagesmatching to get the version of httpd that's currently installed. You might combine it with ifelse, strcmp, regcmp so that you can set different variables and classes which you might use in your template.

0
On

I use CFEngine (3.9) on CentOS 7.3. This version sets a hard class centos. You can use this to create the different sections. (Is also sets a hard class redhat, because CentOS is a derived from RedHat). You can find the classes that are availabe on your system with:

cf-promises -v