Linux - Bash - Get $Releasever and $Basearch Values

Linux - Bash - Get $releasever and $basearch values?

Most distro uses the distroverpkg version to get the releasever and basearch.

If you look at /etc/yum.conf, you will see that distrover is set to redhat-release (for RHEL), enterpriselinux-release (for OEL), and others.

To get the package name:

distro=$(sed -n 's/^distroverpkg=//p' /etc/yum.conf)

To get the releasever:

releasever=$(rpm -q --qf "%{version}" -f /etc/$distro)

To get the basearch:

basearch=$(rpm -q --qf "%{arch}" -f /etc/$distro)

The new code above will try to get the package associated with a file /etc/$distro. Some Linux adds /etc/redhat-release to their package release.

If you get file not owned by any package then use the /etc/*-release file that came with your distro. It is probably /etc/centos-release.

You can check the appropriate /etc/*-release appropriate for this code by checking which file is packaged with centos.

rpm -qf /etc/*-release

Then use this file instead of the first line above.

distro=/etc/centos-release

Here's an example from OEL where /etc/redhat-release is packaged as enterprise-release.

rpm -q --qf "%{name}" -f /etc/redhat-release

Output:

enterprise-release

How to get the value of variables in centos7 repo file?

These aren't shell variables, so you would not expect to be able to print them in bash. These are values that are provided by yum. This answer discusses how to get them programatically, but in general:

  • releasever is the major version of your CentOS release; basically, rpm -q --qf='%{VERSION}\n' centos-release
  • basearch is your system architecture, which you can find with uname -m
  • There is no arch variable
  • infra is apparently something new and may not be used, based on this post

There is some documentation here, which while old-ish is still accurate.

yum_repository module fails properly insert *repo configuration file

It seems like yum couldn't determine $releasever and $basearch. Check this post for the possible reasons why this wasn't possible.

To workaround the problem, you could try using the yum module instead:

- name: install the latest version of epel
yum:
name: epel-release
state: latest

Or install it directly from the rpm package:

- name: install from url
yum:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
state: present

Install fresh copies of centos 7 base repos

Assuming you are running CentOS-7.3, you can get back the repo files the following way,

# ReInstall the centos-release rpm
~]# rpm -Uvh --force \
http://mirror.centos.org/centos-7/7/os/x86_64/Packages/centos-release-7-3.1611.el7.centos.x86_64.rpm

# Clean YUM cache
~]# yum clean all

# Try an update
~]# yum update

centos-release RPM contains all the repo files,

~]#  rpm -qlp \
http://mirror.centos.org/centos-7/7/os/x86_64/Packages/centos-release-7-3.1611.el7.centos.x86_64.rpm 2>/dev/null | grep repo
/etc/yum.repos.d/CentOS-Base.repo
/etc/yum.repos.d/CentOS-CR.repo
/etc/yum.repos.d/CentOS-Debuginfo.repo
/etc/yum.repos.d/CentOS-Media.repo
/etc/yum.repos.d/CentOS-Sources.repo
/etc/yum.repos.d/CentOS-Vault.repo
/etc/yum.repos.d/CentOS-fasttrack.repo

Ansible 2.3.1.0: Enable repo on CENTOS 7

You can do this to issue that specific shell command:

- name: enable remi-php71
shell: yum-config-manager --enable remi-php71

Although it is probably better to declare the yum repo itself via something like:

- name: Add remi-php71
yum_repository:
name: remi-php71
description: Remi's PHP 7.1 RPM repository for Enterprise Linux $releasever - $basearch
mirrorlist: http://rpms.remirepo.net/enterprise/$releasever/php71/mirror
enabled: yes
gpgcheck: 1
gpgkey: http://rpms.remirepo.net/RPM-GPG-KEY-remi

Docs here and here.

Can't clone a github repo on Linux via HTTPS

The answer was simple but not obvious:

Instead of:

git clone https://github.com/org/project.git

do:

git clone https://username@github.com/org/project.git

or (insecure)

git clone https://username:password@github.com/org/project.git

(Note that in the later case, your password will may be visible by other users on your machine by running ps u -u $you and will appear cleartext in your shell's history by default)

All 3 ways work on my Mac, but only the last 2 worked on the remote Linux box. (Thinking back on this, it's probably because I had a global git username set up on my Mac, whereas on the remote box I did not? That might have been the case, but the lack of prompt for a username tripped me up... )

Haven't seen this documented anywhere, so here it is.



Related Topics



Leave a reply



Submit