[SOLVED] Prevent yum to change the content of /etc/yum.repos.d

Issues related to applications and software problems
Post Reply
drknut
Posts: 50
Joined: 2016/12/13 11:59:42

[SOLVED] Prevent yum to change the content of /etc/yum.repos.d

Post by drknut » 2021/05/15 02:14:10

Dear All,

In my /etc/yum.repos.d directory, the default .repo files (e.g. CentOS-Base.repo) are replaced by custom files pointing to a local repository.

Sometimes, when doing an update, yum reinstalls the default .repo files.

Is there a way to protect the content of /etc/yum.repos.d while keeping the yum package up to date ?
Last edited by drknut on 2021/05/15 11:39:00, edited 1 time in total.

User avatar
TrevorH
Forum Moderator
Posts: 30770
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Prevent yum to change the content of /etc/yum.repos.d

Post by TrevorH » 2021/05/15 03:29:00

It should never replace modified files in that directory, they are all marked as config,noreplace in the spec file. It will however, put them back if they are removed.
CentOS 6 died in November 2020 - migrate to a new version!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

drknut
Posts: 50
Joined: 2016/12/13 11:59:42

Re: Prevent yum to change the content of /etc/yum.repos.d

Post by drknut » 2021/05/15 03:40:43

TrevorH wrote:
2021/05/15 03:29:00
It will however, put them back if they are removed.
That's my problem. But I see an easy solution : let these files in place and edit them enable=1 => enable=0.

Do you see a better solution ?

User avatar
jlehtone
Posts: 3532
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Prevent yum to change the content of /etc/yum.repos.d

Post by jlehtone » 2021/05/15 07:37:04

drknut wrote:
2021/05/15 03:40:43
I see an easy solution : let these files in place and edit them enable=1 => enable=0.
That is a good solution.

I did use to edit files manually. Error-prone.

Yum-utils has tool for it:

Code: Select all

sudo yum-config-manager --disable base updates extras
Since shifting to Ansible for config management, I have had Ansible task:

Code: Select all

    - name: Disable upstream base mirrors
      ini_file:
        dest: /etc/yum.repos.d/CentOS-Base.repo
        section: "{{ item }}"
        option: enabled
        value: "0"
      with_items:
        - base
        - updates
        - extras
And naturally tasks to define "custom files". An example:

Code: Select all

    - name: Add {{ site_name | upper }} base
      yum_repository:
        name: "{{ site_name }}-base"
        description: CentOS $releasever - $basearch - {{ site_name | upper }}
        file: "{{ site_name }}-mirror"
        baseurl: "{{ site_mirror }}/$releasever/os/$basearch/"
        gpgcheck: yes
        gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-{{ ansible_distribution_major_version }}
        metadata_expire: 7d

drknut
Posts: 50
Joined: 2016/12/13 11:59:42

Re: Prevent yum to change the content of /etc/yum.repos.d

Post by drknut » 2021/05/15 11:37:45

jlehtone wrote:
2021/05/15 07:37:04
Yum-utils has tool for it:

Code: Select all

sudo yum-config-manager --disable base updates extras
It works, but it disables all repos having sections like [base] [updates] [extra], so it disables my custom repos too.

Luckily there is an option (-c) to specify the config file. One at time, because it fails on duplicate sections.

[edit] This doesn't work, see my post below
For me, it translates to

Code: Select all

for f in /etc/yum.repos.d/CentOS*; do yum-config-manager -c $f '--disablerepo=*'; done
[/edit]

Of course, none of my custom files begins with 'CentOS'.

Thank you for your help, jlehtone.
Last edited by drknut on 2021/05/15 12:17:30, edited 1 time in total.

drknut
Posts: 50
Joined: 2016/12/13 11:59:42

Re: [SOLVED] Prevent yum to change the content of /etc/yum.repos.d

Post by drknut » 2021/05/15 12:13:46

The "solution" posted above, based on yum-config-manager, doesn't work at all.

Why ? because the enable/disable function needs a line with "enabled =" in the target section.

yum-config-manager doesn't add such a line if it is missing.

So my final solution is, so far :-(

Code: Select all

for f in /etc/yum.repos.d/CentOS*; do truncate -s 0 $f; done

User avatar
jlehtone
Posts: 3532
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Prevent yum to change the content of /etc/yum.repos.d

Post by jlehtone » 2021/05/15 15:51:19

drknut wrote:
2021/05/15 11:37:45
It works, but it disables all repos having sections like [base] [updates] [extra], so it disables my custom repos too.
man yum.conf wrote:repositoryid Must be a unique name for each repository, one word.
If you have [base] in more than once, then your repositoryid's are not unique.
That problem is your own doing.

drknut wrote:
2021/05/15 12:13:46
the enable/disable function needs a line with "enabled =" in the target section.
yum-config-manager doesn't add such a line if it is missing.
You were disabling CentOS repositories. Are there any that do not have the 'enabled' option?

Furthermore, the "--disable" does add the 'enabled = 0'.
(The "--enable" does not add the missing 'enabled' option because the default is enabled.)


The yum-config-manager is fully functional unless the input data is garbage.

drknut
Posts: 50
Joined: 2016/12/13 11:59:42

Re: Prevent yum to change the content of /etc/yum.repos.d

Post by drknut » 2021/05/15 16:12:02

jlehtone wrote:
2021/05/15 15:51:19
The yum-config-manager is fully functional unless the input data is garbage.
Your are totally right. I plead guilty of not RTFM.

You probably never do that, so feel free to throw the first stone.

Anyway, I sincerely appreciate the help you provided to a poor sinner. Thanx again.

Post Reply

Return to “CentOS 7 - Software Support”