Question

I am facing a issue while trying configuring something with CFENGINE3.5, I have created a policy to install some package from source, which download tar balls from some url and then untar it and further digs it with make and make install, everything working fine except while it download tar balls it keeps at "/etc" location, I want cfengine to put this file at /tmp.

Is there any way to customize this default behavior of cfengine to keep all temporary downloaded files at "/tmp" instead of "/etc".

Here is the Policy snippet:

bundle agent install
{
  vars:
      "packages" slist => {
                            "Algorithm-Diff-1.1902",
                            "Apache-DB-0.13",
                            "Apache-DBI-1.06",
                            "Apache-Session-1.83",
                            "Apache-SessionX-2.01",
                            "AppConfig-1.65",
                            "Archive-Tar-1.32",
      };

  commands:
      "/usr/bin/wget http://10.X.X.X/downloads/perl-modules/$(packages).tar.gz;
/usr/bin/gunzip $(packages).tar.gz;
tar -xf $(packages).tar;
cd $(packages);
/usr/bin/perl Makefile.PL;
/usr/bin/make;
/usr/bin/make install;"
        contain =>  standard,
        classes => satisfied(canonify("$(packages)-installed"));
}

body contain standard
{
        useshell => "true";
        exec_owner => "root";
} 

Thanks in advance.

Was it helpful?

Solution

You can add the directory in which the commands should be executed to the contain body, like this:

body contain standard
{
  useshell => "true";
  exec_owner => "root";
  chdir => "/tmp";
}

Please note there are already a few contain bodies in the standard library (lib/3.5/commands.cf), maybe one of those can be used so you don't have to write your own. Note that CFEngine already executes as root, so exec_owner => "root" is not strictly necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top