Skip to content

Instantly share code, notes, and snippets.

@teroka
Created July 19, 2013 14:04
Show Gist options
  • Save teroka/6039346 to your computer and use it in GitHub Desktop.
Save teroka/6039346 to your computer and use it in GitHub Desktop.
body common control
{
bundlesequence => { "test_apt" };
inputs => { "cfengine_stdlib.cf" };
}
bundle agent test_apt
{
vars:
"curver" string => "23.3+1-1ubuntu9.2";
"pkgver" slist => { "23.3+1-1ubuntu9.0", "23.3+1-1ubuntu9.2", "23.3+1-1ubuntu9.4" };
"select" slist => { ">", "<", "==", "!=", ">=", "<=" };
"handles" slist => { "greaterthan", "lessthan", "equal", "notequal", "greater_or_equal", "less_or_equal" };
packages:
"emacs"
handle => "greaterthan",
package_policy => "verify",
package_method => apt_get,
package_select => "$(select)",
package_version => "$(pkgver)",
classes => if_else("yes_$(this.handle)_${pkgver}","no_$(this.handle)_${pkgver}"),
ifvarclass => and(strcmp("$(select)",">"));
"emacs"
handle => "lessthan",
package_policy => "verify",
package_method => apt_get,
package_select => "$(select)",
package_version => "$(pkgver)",
classes => if_else("yes_$(this.handle)_${pkgver}","no_$(this.handle)_${pkgver}"),
ifvarclass => and(strcmp("$(select)","<"));
"emacs"
handle => "equal",
package_policy => "verify",
package_method => apt_get,
package_select => "$(select)",
package_version => "$(pkgver)",
classes => if_else("yes_$(this.handle)_${pkgver}","no_$(this.handle)_${pkgver}"),
ifvarclass => and(strcmp("$(select)","=="));
"emacs"
handle => "notequal",
package_policy => "verify",
package_method => apt_get,
package_select => "$(select)",
package_version => "$(pkgver)",
classes => if_else("yes_$(this.handle)_${pkgver}","no_$(this.handle)_${pkgver}"),
ifvarclass => and(strcmp("$(select)","!="));
"emacs"
handle => "greater_or_equal",
package_policy => "verify",
package_method => apt_get,
package_select => "$(select)",
package_version => "$(pkgver)",
classes => if_else("yes_$(this.handle)_${pkgver}","no_$(this.handle)_${pkgver}"),
ifvarclass => and(strcmp("$(select)",">="));
"emacs"
handle => "less_or_equal",
package_policy => "verify",
package_method => apt_get,
package_select => "$(select)",
package_version => "$(pkgver)",
classes => if_else("yes_$(this.handle)_${pkgver}","no_$(this.handle)_${pkgver}"),
ifvarclass => and(strcmp("$(select)","<="));
reports:
cfengine::
"Installed emacs version \"$(curver)\" is $(handles) --> \"$(pkgver)\""
ifvarclass => and(canonify("yes_$(handles)_${pkgver}"));
"Installed emacs version \"$(curver)\" is NOT $(handles) --> \"$(pkgver)\""
ifvarclass => and(canonify("no_$(handles)_${pkgver}"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment