0

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.

Greg
  • 8,230
  • 5
  • 38
  • 53
  • from httpd configuration perspective you can use IfModule or IfVersion with the help of mod_version module. Have you tried it? – Daniel Ferradal Oct 17 '16 at 13:58
  • No, but I don't want to rely on an additional module mod_version which may not be installed. – Greg Oct 17 '16 at 19:30

2 Answers2

1

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.

Nick Anderson
  • 316
  • 1
  • 4
  • https://docs.cfengine.com/lts/reference-functions-packagesmatching.html https://docs.cfengine.com/lts/reference-functions-ifelse.html https://docs.cfengine.com/lts/reference-functions-strcmp.html https://docs.cfengine.com/lts/reference-functions-regcmp.html – Nick Anderson Oct 18 '16 at 09:09
  • Is there anything that would be available in CFEngine 3.3? – Greg Oct 21 '16 at 22:29
  • The opportunity to upgrade to 3.7+ :-). But really, you could use the module protocol to do all the logic in a script and then define useful classes and vars, returnszero with. The right package manager query, or execresult maybe with regcmp or strcmp – Nick Anderson Oct 21 '16 at 22:39
  • @NickAnderson Hi Nick - can you take a look at my (similar) question https://stackoverflow.com/q/46845164/892318 .... thx in advance – domi27 Oct 20 '17 at 08:30
  • Sure, commented. – Nick Anderson Oct 20 '17 at 14:31
0

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

user1728943
  • 105
  • 4