Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
This is a terrible way to go about it. It will return different and quite possibly wrong results on different systems. (I'm sure that you don't want "Enterprise" if you run it on an actual RHEL box.) Just use facter operatingsystemrelease. –  Michael Hampton Aug 11 at 23:51
    
I am trying to do this outside of puppet, and the result will always be the same on a redhat or cent box... –  Party Time Aug 12 at 0:09
    
I didn't say anything about puppet. It's fairly common to use facter with ansible, for instance. –  Michael Hampton Aug 12 at 0:17
    
So your suggestion is install facter, and store the yum variable as the output of 'facter operatingsystemrelease'? That is all well and good but doesn't answer the root of my question which is, how to create a yum variable that is the result of a command. The command to return the dot release of my os is irrelevant. –  Party Time Aug 12 at 0:24
    
@PartyTime How are you distributing the .repo file? Distribute one to your RHEL 6.2 servers and another to your 6.5 servers. Or you can build them dynamically, which is where the facter comes in handy. But is the software for EL6.2 considerably different than EL6.5? –  ewwhite Aug 12 at 0:47

1 Answer 1

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.

share|improve this answer
    
I am trying to do this outside of puppet. We maintain multiple versions of rhel and centos in house, so I need to have a repo for my 6.2 hosts, and a repo for my 6.5 hosts –  Party Time Aug 12 at 0:08
1  
You can still use the facter tool without Puppet. –  ewwhite Aug 12 at 0:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.