Need to execute yum commands

Greetings Pro’s

I’m trying to execute a command "yum install kernel-devel-“kernel version” on rhel machines. each server has different kernel version , which im trying to perform manually .

if “uname -r” returns “3.10.0-514.6.2.el7.x86_64”,

then i run “yum install kernel-devel-3.10.0-514.6.2.el7.x86_64”

can this be automated using chef?

i tried a recipe by using execute resource and added ruby code to pull the kernal version in the command, but fails

Please help.

execute 'yum ’ do
command “yum install kernel-devel-<% uname -r %>”

Yes. it can. But this can be unreliable. The RPM may no longer be available in the repositories of a running RHEL system, or may have conflicts with the installed kernel if you’ve ever done “yum update kernel”. It takes thought about how kernel RPM’s work to do do a reliable kernel update.

Is there any reason you’re not simply including “kernel” with “kernel-devel”, to help ensure the availability of the kernel running on the system, which may have otherwise been upgraded and flushed?

Hi nkadel,
yes the reason why i not simply including kernel is because, we have Symantec agent installed on all linux servers and one of its Auto protection component is Malfunctioning to remediate that issue we had to follow the steps give my SEP engineers and one of the steps include this command kernel-devel’s one. so though chef might be helpful in reducing the task.

We wrote a script (which I cannot share) to run at boot before SEP for Linux is started. It determines whether or not there are appropriately matching SEP kernel modules for the kernel just booted and, if needed, rebuilds the SEP for Linux kernel modules. This way Autoprotect is never in the “Malfunctioning” state because of a reason that has to do with kernel + SEP module mismatch.

It looks like you are checking the installed version of the kernel than installing the corresponding kernel-devel package.

If that’s the case you could use one of the node attributes, perhaps node[‘kernel’][‘release’], to determine the kernel version, read it into a variable then use that to install the proper kernel-devel with the ‘yum_package’ resource in your recipe.

Bart can you please give me a simple example . That would be more clear and understanding to me.

Thank you :slight_smile:

What _bart wanted to mention here to use the ohai instead of Linux native commands. If you login to one of machine you can run this command: ohai. As it will be a long story it is better to direct immediately to a file e.g.: ohai > /tmp/ohai.txt.

You can get these attributes also from Chef UI if you look for the node and expand the attributes.

Open it and you can search for ‘kernel’ word. You can use these values to prepare an if statement

if node[:kernel][:release] etc…

Also you can use the embedded yum resource:

yum_package ‘kernel-devel’ do
version ‘3.10.0-514.6.2.el7’

Thank you mrimoczy its more clear now … :slight_smile: