Yum: How can I view variables like $releasever, $basearch & $YUM0?
When this answer was written in 2011, json wasn't installed for python by default for all the versions of RHEL/CentOS at that time so I used pprint to print the stuff nicely.
It is now 2020 and all current versions of RHEL/CentOS have json by default for python. The answer has been updated to use json and updated to include RHEL/CentOS 8 by modifying @sysadmiral's answer for Fedora.
RHEL/CentOS 8:
/usr/libexec/platform-python -c 'import dnf, json; db = dnf.dnf.Base(); print(json.dumps(db.conf.substitutions, indent=2))'
RHEL/CentOS 6 and 7
python -c 'import yum, json; yb = yum.YumBase(); print json.dumps(yb.conf.yumvar, indent=2)'
RHEL/CentOS 4 and 5
# if you install python-simplejson
python -c 'import yum, simplejson as json; yb = yum.YumBase(); print json.dumps(yb.conf.yumvar, indent=2)'
# otherwise
python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)'
Example output:
# CentOS 8:
# ---
[root@0928d3917e32 /]# /usr/libexec/platform-python -c 'import dnf, json; db = dnf.dnf.Base(); print(json.dumps(db.conf.substitutions, indent=2))'
Failed to set locale, defaulting to C
{
"arch": "x86_64",
"basearch": "x86_64",
"releasever": "8"
}
[root@0928d3917e32 /]#
# CentOS 7:
# ---
[root@c41adb7f40c2 /]# python -c 'import yum, json; yb = yum.YumBase(); print json.dumps(yb.conf.yumvar, indent=2)'
Loaded plugins: fastestmirror, ovl
{
"uuid": "cb5f5f60-d45c-4270-8c36-a4e64d2dece4",
"contentdir": "centos",
"basearch": "x86_64",
"infra": "container",
"releasever": "7",
"arch": "ia32e"
}
[root@c41adb7f40c2 /]#
# CentOS 6:
# ---
[root@bfd11c9a0880 /]# python -c 'import yum, json; yb = yum.YumBase(); print json.dumps(yb.conf.yumvar, indent=2)'
Loaded plugins: fastestmirror, ovl
{
"releasever": "6",
"basearch": "x86_64",
"arch": "ia32e",
"uuid": "3e0273f1-f5b6-481b-987c-b5f21dde4310",
"infra": "container"
}
[root@bfd11c9a0880 /]#
Original answer below:
If you install yum-utils
, that will give you yum-debug-dump
which will write those variables and more debugging info to a file. There is no option to write to stdout, it will always write to some file which really isn't that helpful.
This is obviously not a great solution so here's a python one-liner you can copy and paste which will print those variables to stdout.
python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)'
This works on CentOS 5 and 6, but not 4. yum is written in python, so the yum python module is already on your server, no need to install anything exra.
Here's what it looks like on CentOS 5:
[root@somebox]# python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)'
{'arch': 'ia32e',
'basearch': 'x86_64',
'releasever': '5',
'yum0': '200',
'yum5': 'foo'}
[root@somebox]#
Just in case anybody ends up here, like me, looking for the equivalent answer for dnf on Fedora I fathomed out the following python one-liner:
python3 -c 'import dnf, pprint; db = dnf.dnf.Base(); pprint.pprint(db.conf.substitutions,width=1)'
On Fedora 24 it looks like this:
{'arch': 'x86_64',
'basearch': 'x86_64',
'releasever': '24'}
To get all of them you'll need to use code like mmckinst posted, but if you just want to check $releasever
you can run yum version nogroups
on RHEL-6.
The other thing to do, in RHEL-6, is to just create your own in /etc/yum/vars
.