Linux – Create yum variable, that is the result of a command

centoslinuxredhatyum

To clarify, I am looking on how to store a yum variable as the RESULT of a command. The command I use to get the OS version is irrelevant to me, I'm sure there are better ways of getting it than what I've done below.

I want to create a custom yum variable that is the result of running

cat /etc/redhat-release | awk '{ print $3 }'

The documentation for creating variables seems to only allow for creating static variables inside a file in /etc/yum/vars/$variablename.

So what I want is to have /etc/yum/vars/dotrelease be the output of my command above, based on the system I am on.

Then I can set my baseurl repo to http://localrepo.com/repo/centos/$dotrelease/os/$basearch/

My custom repo is separated by dot release, where by default $releasever only looks the numbered release, for example, the $releasever variable on centos6.4 is "6".

I realize I can just

echo (cat /etc/redhat-release | awk '{ print $3 }') > /etc/yum/vars/dotrelease

but I'd have to run that on every machine I deploy, instead of just keeping the variable in a file.

Best Answer

Is puppet in your environment at all?

# facter operatingsystemrelease
6.5

Is quite clean...

But in your local repository, are you actually distributing different packages depending on the point release of your EL system? That may not make sense, as EL tends to automatically move/update to the newest point release within a major version. E.g. You won't see many people running RHEL 6.2 today, because there are no updates available.