0

I want to put body package_method and some variables in promises.cf or in a different file and I should be able to call it from any new CF files I write.

Is that possible? I could not find anything related to such methods in the documentation.

I was thinking of creating a new file in /var/cfengine/masterfiles/ and then edit /var/cfengine/promises.cf and insert the new file as inputs but it did not work out.

Here is what I want to put (in a new file maybe) which should be accessible globally.

bundle common variables
{
   vars:
          "global_var_1" string  => "value_var_1";
}

and

body package_method yum
{
   any::
   package_changes => "bulk";
   package_list_command => "/usr/bin/yum list installed";
   package_list_name_regex => "([^.]+).*";
   package_list_version_regex => "[^\s]\s+([^\s]+).*";
   package_list_arch_regex => "[^.]+\.([^\s]+).*";
   package_installed_regex => ".*installed.*";
   package_name_convention => "$(name).$(arch)";

   package_name_regex => "amanda-client";
   package_arch_regex => "x86_64";
   package_add_command => "/usr/bin/yum -y install";
   package_delete_command => "/bin/rpm -e";
   package_verify_command => "/bin/rpm -V";
}

Then I should be able call it in any new CF as:

"${variables.global_var_1}"

and

bundle agent packages
{
   packages:
           "wget"
                   package_policy => "add",
                   package_method => yum;
}
0

Solved.

To create Global Variables:

Create a variables.cf and in that file insert the following lines.

bundle common variables
{
   vars:
          "global_var_1" string  => "value_var_1";
 }

Then create any CF but under the body common control - input the variables.cf file.

body common control
{
bundlesequence => { "myclasses" };
inputs => { "variables.cf" };
}

Then you can call the variables as "${variables.global_var_1}".

To call package_method globally:

Under any new CF body common control input the file /var/cfengine/masterfiles/lib/packages.cf

body common control
{
bundlesequence => { "myclasses", "packages_to_install" };
inputs => { "/var/cfengine/masterfiles/lib/packages.cf" };
}

Then you can add packages like

bundle agent packages_to_install
{
packages:
          "wget"
                 package_policy => "add",
                  package_method => yum;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.