Skip to content

Instantly share code, notes, and snippets.

@bahamat
Last active August 29, 2015 14:06
Show Gist options
  • Save bahamat/3345b132344ce31b02ff to your computer and use it in GitHub Desktop.
Save bahamat/3345b132344ce31b02ff to your computer and use it in GitHub Desktop.
A cfengine bundle to upgrade all or a list of packages on a Debian system.
bundle agent dpkgup(p_list) {
vars:
done_with_classes.package_list_provided::
"pkg_list" string => join(" ", p_list), policy => "free";
done_with_classes.!package_list_provided::
"pkg_list" string => "", policy => "free";
done_with_classes::
"apt_show_versions" string => execresult("/usr/bin/apt-show-versions -u $(pkg_list)","useshell");
"dim" int => parsestringarray("upgrade","$(apt_show_versions)","NoComments","[/ ]","1000","200000");
"package" slist => getindices("upgrade");
classes:
"package_list_provided" expression => isvariable("p_list");
"done_with_classes" expression => "any";
reports:
"Upgrade $(package) to $(upgrade[$(package)][6])";
packages:
"apt-show-versions"
package_policy => "addupdate",
handle => canonify("$(this.bundlename)_apt_get_install_$(install)"),
package_method => apt_get_permissive;
"$(package)"
package_policy => "addupdate",
handle => canonify("$(this.bundlename)_apt_get_install_$(package)"),
package_method => apt_get,
package_version => "$(upgrade[$(package)][6])",
package_select => ">=";
}
bundle agent rpmup(p_list) {
vars:
done_with_classes.package_list_provided::
"pkg_list" string => join(" ", p_list), policy => "free";
done_with_classes.!package_list_provided::
"pkg_list" string => "", policy => "free";
done_with_classes::
"yum_list_updates" string => execresult("/usr/bin/yum -C list updates $(pkg_list) | grep updates","useshell");
"dim" int => parsestringarray("upgrade","$(yum_list_updates)","NoComments","\s+","1000","200000");
"package" slist => getindices("upgrade");
"p[$(package)]" slist => splitstring("$(package)","\.","1");
classes:
"package_list_provided" expression => isvariable("p_list");
"done_with_classes" expression => "any";
reports:
"Upgrade $(p[$(package)]) to $(upgrade[$(package)][1])";
packages:
"$(p[$(package)])"
package_policy => "addupdate",
handle => canonify("$(this.bundlename)_yum_install_$(package)"),
package_method => yum,
package_version => "$(upgrade[$(package)][1])",
package_select => ">=";
}
bundle agent zypper_up(p_list) {
vars:
package_list_provided::
"pkg_list" slist => { "@(p_list)" };
done_with_classes::
"zyp_show_versions" string => execresult("/usr/bin/zypper lu |awk -F \| '$1~/v/{gsub(\" \",\"\"); print $3,$5}NR==80{nextfile}'","useshell");
"dim" int => parsestringarray("upgrade","$(zyp_show_versions)","NoComments"," *","1000","200000");
"upgradeable" slist => getindices("upgrade");
done_with_classes.package_list_provided::
"package" slist => intersection("upgradeable", "pkg_list");
done_with_classes.!package_list_provided::
"package" slist => { "$(upgradeable)" };
classes:
"package_list_provided" expression => isvariable("p_list");
"done_with_classes" expression => "any";
reports:
"Upgrade $(package) to $(upgrade[$(package)][1])";
packages:
any::
"$(package)"
package_policy => "update",
handle => canonify("$(this.bundlename)_install_$(package)"),
package_method => zypper,
package_version => "$(upgrade[$(package)][1])",
package_select => ">=";
}
@bahamat
Copy link
Author

bahamat commented Sep 12, 2014

Usage:

bundle agent upgrade_all
{
 methods:
    "upgrade" usebundle => dpkgup;
}

Or

bundle agent upgrade_some
{
 vars:
    "p" slist => { "bash", "zsh" };
 methods:
    "upgrade" usebundle => dpkgup("@(upgrade_some.p)");
}

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