I am setting up a yum repository, and need to debug some of the URLs in the yum.conf file. I need to know why is Scientific Linux trying to grab this URL, when I was expecting it to grab another URL:
# yum install package http://192.168.1.100/pub/scientific/6.1/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404" Trying other mirror. Error: Cannot retrieve repository metadata (repomd.xml) for repository: sl. Please verify its path and try again
The yum.conf(5) manpage gives some information about these variables:
Variables
There are a number of variables you can use to ease maintenance of
yum’s configuration files. They are available in the values of several
options including name, baseurl and commands.$releasever This will be replaced with the value of the version of the
package listed in distroverpkg. This defaults to the version of
‘redhat-release’ package.$arch This will be replaced with your
architecture as listed by os.uname()[4] in Python.$basearch This will be replaced with your base architecture in yum.
For example, if your $arch is i686 your $basearch will be i386.$YUM0-$YUM9 These will be replaced with the value of the shell
environment variable of the same name. If the shell environment
variable does not exist then the configuration file variable will not
be replaced.
Is there a way to view these variables by using the yum commandline utility? I would prefer to not hunt down the version of the ‘redhat-release’ package, or manually get the value of os.uname()[4] in Python.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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:
# ---
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c7e6363784c3c353e34683f353d3b693f3e">[email protected]</a> /]# /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"
}
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="592b36362d1969606b613d6a60686e3c6a6b">[email protected]</a> /]#
# CentOS 7:
# ---
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fb8994948fbb98cfca9a9f99cc9dcfcb98c9">[email protected]</a> /]# 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"
}
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="25574a4a5165461114444147124311154617">[email protected]</a> /]#
# CentOS 6:
# ---
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1d3ceced5e1c3c7c59090c298c091999991">[email protected]</a> /]# 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"
}
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3a1bcbca793b1b5b7e2e2b0eab2e3ebebe3">[email protected]</a> /]#
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:
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="05776a6a7145766a6860676a7d">[email protected]</a>]# 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'}
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea9885859eaa9985878f888592">[email protected]</a>]#
Method 2
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'}
Method 3
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.
Method 4
And drilling down how $releasever is assigned:
The function _getsysver query the rpm database like:
rpm -q --provides $(rpm -q --whatprovides "system-release(releasever)") | grep "system-release(releasever)" | cut -d ' ' -f 3
“system-release(releasever)” value is defined here, and it could be override by distroverpkg in yum.conf
If the query did not return any value, releasever is set to ‘$releasever’ (for example if you set distroverpkg=centos-release but have installed the rpm redhat-release-server)
Method 5
For a full dump you can use:
$ yum config-manager --dump or $ dnf config-manager --dump
To dump variables you can use:
$ yum config-manager --dump-variables or $ dnf config-manager --dump-variables
yum-config-manager is also available but typically redirects to the DNS config-manager Plugin
From https://linux.die.net/man/5/yum.conf:
$releasever This will be replaced with the value of the version of the package listed in distroverpkg. This defaults to the version of ‘redhat-release’ package.
$arch This will be replaced with your architecture as listed by os.uname()[4] in Python.
$basearch This will be replaced with your base architecture in yum. For example, if your $arch is i686 your $basearch will be i386.
$uuid This will be replaced with a unique but persistent uuid for this machine. The value that is first generated will be stored in /var/lib/yum/uuid and reused until this file is deleted.
$YUM0-$YUM9 These will be replaced with the value of the shell environment variable of the same name. If the shell environment variable does not exist then the configuration file variable will not be replaced.
Files
/etc/yum.conf
/etc/yum.repos.d/
/etc/yum/pluginconf.d/
/etc/yum/protected.d
/etc/yum/vars
Method 6
For CentOS 8 Stream, which uses more variables like $stream – you can also do this:-
# cd /etc/dnf/vars;grep . *
which reveals them thusly:-
contentdir:centos infra:stock stream:8-stream
Method 7
Another way to see the results of variable substitution is to do something like this:
yum-config-manager -c /etc/reposyncb.conf | grep -i spacewalk
I was tinkering with yum variables to control which spacewalk client is selected for building a local repo and found this useful to see how the variables are being interpreted.
Method 8
Getting the value for $arch should really be as simple as arch="$(arch)" or arch="$(uname --machine)" but if you really want to know what yum‘s value for $arch is, try:
bash-4.2# arch="$(python -c 'from rpmUtils import arch; print(arch.getCanonArch());')"; bash-4.2# declare -p arch declare -- arch="ia32e"
Getting the values for the other vars without needing to use Python is a little easier.
Option 1:
bash-4.2# distroverpkg="$(awk --field-separator = '/distroverpkg/{print$2}' /etc/yum.conf)";
bash-4.2# releasever="$(rpm --query --queryformat '%{VERSION}n' "${distroverpkg:-redhat-release}")";
bash-4.2# basearch="${HOSTTYPE:-$(uname --machine)}";
bash-4.2# declare -p distroverpkg releasever basearch
declare -- distroverpkg="centos-release"
declare -- releasever="7"
declare -- basearch="x86_64"
Option 2:
bash-4.2# releasever="$(rpm --query --file --queryformat '%{VERSION}n' /etc/system-release)";
bash-4.2# basearch="$(rpm --query --queryformat '%{ARCH}n' "kernel-$(uname --kernel-release)")";
bash-4.2# declare -p releasever basearch
declare -- releasever="7"
declare -- basearch="x86_64"
Note: Commands shown using
long-opts(when available) for clarity.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0