1

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.

Party Time
  • 155
  • 6
  • 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 '14 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 '14 at 00:09
  • I didn't say anything about puppet. It's fairly common to use facter with ansible, for instance. – Michael Hampton Aug 12 '14 at 00: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 '14 at 00: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 '14 at 00:47
  • I currently do distribute different repo files at build time (kickstart) but would love to not have to explicitly define the version number. Also in the future it would simplify pushing out my repo configs if they ever have to change. I suppose I will have to just do it at build time, in the kickstart. thanks for your ideas – Party Time Aug 12 '14 at 01:35

1 Answers1

0

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.

ewwhite
  • 197,159
  • 92
  • 443
  • 809
  • 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 '14 at 00:08
  • 1
    You can still use the `facter` tool without Puppet. – ewwhite Aug 12 '14 at 00:12