Skip to content

Instantly share code, notes, and snippets.

@jan-matejka
Created July 26, 2012 12:09
Show Gist options
  • Select an option

  • Save jan-matejka/3181697 to your computer and use it in GitHub Desktop.

Select an option

Save jan-matejka/3181697 to your computer and use it in GitHub Desktop.
body common control {
bundlesequence => {
base,
g,
};
inputs => {
"cfengine_stdlib.cf",
};
}
bundle agent base {
vars:
"sys" slist => {
"A", "B", "C"
};
commands:
"/bin/true"
classes => if_ok("${sys}");
reports:
linux::
"setting up ${sys}";
}
bundle agent g {
vars:
A::
"fok[1]" string => "foka";
B::
"fok[2]" string => "fokb";
C::
"fok[3]" string => "fokc";
any::
"fok_idx" slist => getindices("fok");
reports:
linux::
"foks: ${fok_idx}";
"${fok[1]}";
}
# cf-agent -f test.cf result:
# R: setting up A
# R: setting up B
# R: setting up C
# R: foka
@zzamboni
Copy link

Another one related to this bug: https://cfengine.com/bugtracker/view.php?id=904

You need to condition getindices() so that it happens on the second pass, like this:

body common control {
        bundlesequence => {
                            base,
                            g,
                          };

        inputs => {
                    "/var/cfengine/inputs/cfengine_stdlib.cf",
                  };
                    }


bundle agent base {
  vars:
      "sys" slist => {
                       "A", "B", "C"
                     };

  commands:
      "/usr/bin/true"
        classes => if_ok("${sys}");

  reports:
    cfengine::
      "setting up ${sys}";
                  }

bundle agent g {
  vars:
    A::
      "fok[1]" string => "foka";


    B::
      "fok[2]" string => "fokb";


    C::
      "fok[3]" string => "fokc";

    secondpass::
      "fok_idx" slist => getindices("fok");
  classes:
      "secondpass" expression => "any";
  reports:
    cfengine::
      "foks: ${fok_idx}";
      "${fok[1]}";
               }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment