Forum: CFEngine Help Subject: Re: CFEngine Help: Re: CFEngine Help: How-to restart machine after certain package have been installed. Author: juriskrumins Link to topic: https://cfengine.com/forum/read.php?3,26673,26720#msg-26720
yum package method body is not modified. Comes from cfengine_std.cf library for 3.3.5 version of cfengine. The only thing I've changed yesterday is package_list_update_ifelapsed => "0" but it's only for testing purpose and I'm going to leave it 240 in production and define new package_method. By the way seems like yum_rpm method works a bit faster that yum. body package_method yum { package_changes => "bulk"; package_list_command => "/usr/bin/yum list installed"; package_patch_list_command => "/usr/bin/yum check-update"; # Remember to escape special characters like | package_list_name_regex => "([^.]+).*"; package_list_version_regex => "[^\s]\s+([^\s]+).*"; package_list_arch_regex => "[^.]+\.([^\s]+).*"; package_installed_regex => ".*(installed|\s+@).*"; package_name_convention => "$(name).$(arch)"; # set it to "0" to avoid caching of list during upgrade #package_list_update_ifelapsed => "240"; package_list_update_ifelapsed => "0"; package_patch_installed_regex => "^[^*]\s.*"; package_patch_name_regex => "([^.]+).*"; package_patch_version_regex => "[^\s]\s+([^\s]+).*"; package_patch_arch_regex => "[^.]+\.([^\s]+).*"; package_add_command => "/usr/bin/yum -y install"; package_update_command => "/usr/bin/yum -y update"; package_delete_command => "/bin/rpm -e --nodeps"; package_verify_command => "/bin/rpm -V"; } ## body package_method yum_rpm # Contributed by Trond Hasle Amundsen # More efficient package method for RedHat - uses rpm to list instead of yum # Notes: # - using $(name).$(arch) instead of $(name) for package_name_convention # causes uninstallation to fail. # - using allmatches to remove for all architectures # { package_changes => "bulk"; package_list_command => "/bin/rpm -qa --qf '%{name} %{version}-%{release} %{arch}\n'"; package_patch_list_command => "/usr/bin/yum check-update"; package_list_name_regex => "^(\S+?)\s\S+?\s\S+$"; package_list_version_regex => "^\S+?\s(\S+?)\s\S+$"; package_list_arch_regex => "^\S+?\s\S+?\s(\S+)$"; package_installed_regex => ".*"; package_name_convention => "$(name)"; # set it to "0" to avoid caching of list during upgrade package_list_update_ifelapsed => "240"; package_patch_installed_regex => "^[^*]\s.*"; package_patch_name_regex => "([^.]+).*"; package_patch_version_regex => "[^\s]\s+([^\s]+).*"; package_patch_arch_regex => "[^.]+\.([^\s]+).*"; package_add_command => "/usr/bin/yum -y install"; package_update_command => "/usr/bin/yum -y update"; package_delete_command => "/bin/rpm -e --nodeps --allmatches"; package_verify_command => "/bin/rpm -V"; } Test bundle code (same as previous, except for commands promise): bundle agent packages { vars: !vz_hardware_node.!vz_container:: "kernel_package" slist => { "mc", }, comment => "Define kernel to install arch specifi", handle => "packages_vars_kernel_package"; packages: !vz_hardware_node.!vz_container:: "$(packages.kernel_package)" package_policy => "add", package_architectures => { "x86_64" }, package_method => yum_rpm, classes => if_repaired("restart_machine"); } 1. This output is for yum_rpm method with mc paackage not installed. cf3> ***************************************************************** cf3> BUNDLE packages cf3> ***************************************************************** cf3> cf3> cf3> ========================================================= cf3> vars in bundle packages (1) cf3> ========================================================= cf3> cf3> cf3> + Private classes augmented: cf3> cf3> - Private classes diminished: cf3> cf3> cf3> cf3> ========================================================= cf3> packages in bundle packages (1) cf3> ========================================================= cf3> cf3> cf3> ......................................................... cf3> Promise's handle: cf3> Promise made by: "mc" cf3> ......................................................... cf3> cf3> -> Cache file exists and is sufficiently fresh according to (package_list_update_ifelapsed) cf3> ??????????????????????????????????????????????????????????????? cf3> Reading package list from /bin/rpm cf3> ??????????????????????????????????????????????????????????????? cf3> -> Package (kernel-firmware,2.6.32-279.1.1.el6,noarch) found cf3> -> Package (basesystem,10.0-4.el6,noarch) found cf3> -> Package (dhclient,4.1.1-31.P1.el6,x86_64) found cf3> -> Package (openssh-server,5.3p1-81.el6,x86_64) found cf3> -> Package (crontabs,1.10-33.el6,noarch) found cf3> -> Package (ncurses-libs,5.7-3.20090208.el6,x86_64) found cf3> -> Package (rng-tools,2-13.el6_2,x86_64) found cf3> -> Package (zlib,1.2.3-27.el6,x86_64) found cf3> -> Package (abrt-cli,2.0.8-6.el6.centos,x86_64) found cf3> Package line did not match one of the package_list_(name|version|arch)_regex patterns cf3> ??????????????????????????????????????????????????????????????? cf3> Reading patches from /usr/bin/yum cf3> ??????????????????????????????????????????????????????????????? cf3> -> Package (bind-libs,32:9.8.2-0.10.rc1.el6_3.1,x86_64) found cf3> -> Package (bind-utils,32:9.8.2-0.10.rc1.el6_3.1,x86_64) found cf3> -> Package (kernel,2.6.32-279.2.1.el6,x86_64) found cf3> -> Package (kernel-firmware,2.6.32-279.2.1.el6,noarch) found cf3> -> Package (kpartx,0.4.9-56.el6_3.1,x86_64) found cf3> -> Package (vzkernel-firmware,2.6.32-042stab057.1,noarch) found cf3> -> Package (kernel-firmware,2.6.32-279.1.1.el6,noarch) found cf3> # Patch reporting feature is only available in version Nova and above cf3> ??????????????????????????????????????????????????????????????? cf3> Done checking packages and patches cf3> ??????????????????????????????????????????????????????????????? cf3> -> Package version was not specified cf3> ... trying listed arch x86_64 cf3> -> Looking for (mc,*,x86_64) cf3> No installed packages matched (mc,*,x86_64) cf3> -> Looking for (mc,*,x86_64) cf3> No installed packages matched (mc,*,x86_64) cf3> Checking if package (mc,*,x86_64) is at the desired state (installed=0,matched=0) cf3> -> Package promises to refer to itself as "mc" to the manager cf3> -> Package version seems to match criteria cf3> -> Schedule package for addition cf3> -> Package (mc,any,any) found cf3> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> cf3> Offering these package-promise suggestions to the managers cf3> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> cf3> -> Deletion schedule... cf3> -> Addition schedule... cf3> Execute scheduled package addition cf3> Command prefix: /usr/bin/yum -y install cf3> Executing /usr/bin/yum -y install mc ... cf3> Q: yum -y install mc ...:Loaded plugins: fastestmirror, security cf3> Q: yum -y install mc ...:Loading mirror speeds from cached hostfile cf3> Q: yum -y install mc ...:Setting up Install Process cf3> Q: yum -y install mc ...:Resolving Dependencies cf3> Q: yum -y install mc ...:--> Running transaction check cf3> Q: yum -y install mc ...:---> Package mc.x86_64 1:4.7.0.2-3.el6 will be installed cf3> Q: yum -y install mc ...:--> Finished Dependency Resolution cf3> Q: yum -y install mc ...: cf3> Q: yum -y install mc ...:Dependencies Resolved cf3> Q: yum -y install mc ...: cf3> Q: yum -y install mc ...:================================================================================ cf3> Q: yum -y install mc ...: Package Arch Version Repository Size cf3> Q: yum -y install mc ...:================================================================================ cf3> Q: yum -y install mc ...:Installing: cf3> Q: yum -y install mc ...: mc x86_64 1:4.7.0.2-3.el6 base 1.6 M cf3> Q: yum -y install mc ...: cf3> Q: yum -y install mc ...:Transaction Summary cf3> Q: yum -y install mc ...:================================================================================ cf3> Q: yum -y install mc ...:Install 1 Package(s) cf3> Q: yum -y install mc ...: cf3> Q: yum -y install mc ...:Total download size: 1.6 M cf3> Q: yum -y install mc ...:Installed size: 5.4 M cf3> Q: yum -y install mc ...:Downloading Packages: cf3> Q: yum -y install mc ...:Running rpm_check_debug cf3> Q: yum -y install mc ...:Running Transaction Test cf3> Q: yum -y install mc ...:Transaction Test Succeeded cf3> Q: yum -y install mc ...:Running Transaction Installing : 1:mc-4.7.0.2-3.el6.x86_64 1/1 Verifying : 1:mc-4.7.0.2-3.el6.x86_64 1/1 cf3> Q: yum -y install mc ...: cf3> Q: yum -y install mc ...:Installed: cf3> Q: yum -y install mc ...: mc.x86_64 1:4.7.0.2-3.el6 cf3> Q: yum -y install mc ...: cf3> Q: yum -y install mc ...:Complete! cf3> Q: yum -y install mc ...: cf3> -> Finished command related to promiser "mc" -- succeeded cf3> ?> defining promise result class restart_machine cf3> Bulk package schedule execution ok for mc (outcome cannot be promised by cf-agent) cf3> -> Update schedule... cf3> -> Patch schedule... cf3> -> Verify schedule... 2. This output is for yum_rpm method with mc package have been installed previously. ... cf3> -> Package (lvm2-libs,2.02.95-10.el6,x86_64) found cf3> Package line did not match one of the package_list_(name|version|arch)_regex patterns cf3> ??????????????????????????????????????????????????????????????? cf3> Reading patches from /usr/bin/yum cf3> ??????????????????????????????????????????????????????????????? cf3> -> Package (bind-libs,32:9.8.2-0.10.rc1.el6_3.1,x86_64) found cf3> -> Package (bind-utils,32:9.8.2-0.10.rc1.el6_3.1,x86_64) found cf3> -> Package (kernel,2.6.32-279.2.1.el6,x86_64) found cf3> -> Package (kernel-firmware,2.6.32-279.2.1.el6,noarch) found cf3> -> Package (kpartx,0.4.9-56.el6_3.1,x86_64) found cf3> -> Package (vzkernel-firmware,2.6.32-042stab057.1,noarch) found cf3> -> Package (kernel-firmware,2.6.32-279.1.1.el6,noarch) found cf3> # Patch reporting feature is only available in version Nova and above cf3> ??????????????????????????????????????????????????????????????? cf3> Done checking packages and patches cf3> ??????????????????????????????????????????????????????????????? cf3> -> Package version was not specified cf3> ... trying listed arch x86_64 cf3> -> Looking for (mc,*,x86_64) cf3> -> Matched name mc cf3> -> Matched arch x86_64 cf3> -> Matched version * cf3> -> Looking for (mc,*,x86_64) cf3> -> Matched name mc cf3> -> Matched arch x86_64 cf3> -> Matched version * cf3> Checking if package (mc,*,x86_64) is at the desired state (installed=1,matched=1) cf3> -> Package promises to refer to itself as "mc" to the manager cf3> -> Package version seems to match criteria cf3> -> Package "mc" already installed, so we never add it again cf3> cf3> ========================================================= cf3> vars in bundle packages (2) cf3> ========================================================= cf3> cf3> ... _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine