Manage Repositories with DNF Config Manager Plugin: 4 Easy Steps

Posted on

Manage Repositories with DNF Config Manager Plugin: 4 Easy Steps

Manage Repositories with DNF Config Manager Plugin: 4 Easy Steps

This guide will show you how to Manage Repositories with DNF Config Manager Plugin in RHEL. As you must know, DNF is the default package manager for RHEL-based distros. It can be used to install, update, and remove packages on your distribution.

If you are a RHEL-based Linux user, you must face with DNF Config Manager plugin in your daily tasks. The DNF config manager plugin is provided by DNF Plugins Core and it can be used to manage repositories on your server. Understanding how to Manage Repositories with DNF Config Manager Plugin is crucial for system administrators and developers working within the Red Hat ecosystem.

In this guide from the Orcacore website, we want to show you the usage of this plugin with examples.

To Manage Repositories with DNF Config Manager Plugin, we will use AlmaLinux 9 as our server. Now follow the steps below to complete this guide.

The Dnf config manager will help you to configure the repositories much more easily.

Step 1 – Dnf Config Manager Syntax Command

The syntax of this command is like the following:

dnf config-manager [options] <section>...

Note: If you face the following error:

dnf-config-manager command not found

You must use the syntax correctly. It shouldn’t have the dash after DNF.

The dnf config-manager plugin must be installed by default in the RHEL-Based distros . If you don’t have it, you can install it by using the command below:

sudo dnf install dnf-plugins-core

Now follow the steps below to see how you can Manage Repositories with DNF Config Manager Plugin.

Step 2 – Add Repositories with DNF Config Manager

At this point, you can use this plugin to add your desired repositories. For this purpose, you should use the --add-repo option with your desired URL. This will help you to add your desired repositories on RHEL. For example:

sudo dnf config-manager --add-repo http://www.example.com/myrepo/

Step 2 – Enable Repositories with DNF Config Manager

After adding your repos, you may want to enable them. This plugin will also help you to enable the repositories by using the --set-enabled option with your added repository. For example:

sudo dnf config-manager --set-enabled myrepo

Step 3 – Disable Repositories with DNF Config Manager

At this point, if you plan to disable your repository, you can easily use the --set-disabled option in the command with your enabled repository. For example:

sudo dnf config-manager --set-disabled myrepo

Step 4 – DNF Config-Manager Options

As you saw, this plugin can help you to configure the repositories much easier. To get more options and usage, you can run the following help command:

sudo dnf config-manager --help-cmd

In the output, you should see:

DNF Config-Manager Options
DNF Config-Manager Options

Conclusion

At this point, you have learned to Manage Repositories with DNF Config Manager Plugin. Just remember that when you want to add and enable a repository, use the repository source you trust. Hope you enjoy it. You may be interested in these articles:

AlmaLinux vs Rocky Linux – Choose Better Distribution

How To Install Java with DNF on AlmaLinux 9

How To Install Node.js on AlmaLinux 8

FAQs

What is the DNF config manager plugin?

This plugin helps you to manage repositories in RHEL-based distros much easier including enabling, adding, and disabling repos.

How to Enable the DNF Config Manager plugin?

This plugin is installed and enabled by default. But if you don’t have it, you can use the command below to install it: sudo dnf install dnf-plugins-core

Alternative Solutions for Managing DNF Repositories

While the dnf config-manager plugin provides a straightforward way to manage repositories, there are alternative methods that offer different levels of control and automation. Here are two alternative approaches:

1. Manually Editing Repository Files:

Instead of using dnf config-manager, you can directly modify the repository configuration files located in the /etc/yum.repos.d/ directory. Each file in this directory represents a repository. These files are plain text files with a specific format. This method gives you fine-grained control over every aspect of the repository configuration.

Explanation:

Each repository is defined within square brackets, like [myrepo]. The file contains key-value pairs that define the repository’s behavior. Important parameters include:

  • name: A human-readable name for the repository.
  • baseurl: The URL where the repository’s packages are located.
  • enabled: Set to 1 to enable the repository or 0 to disable it.
  • gpgcheck: Set to 1 to enable GPG signature verification for packages or 0 to disable it.
  • gpgkey: The URL of the GPG key used to verify package signatures.

Example:

To add a new repository named mycustomrepo manually, you would create a file named mycustomrepo.repo in /etc/yum.repos.d/ with the following content:

[mycustomrepo]
name=My Custom Repository
baseurl=http://www.example.com/mycustomrepo/
enabled=1
gpgcheck=0

After creating or modifying the file, you should clear the DNF cache to ensure that DNF picks up the changes:

sudo dnf clean all

Advantages:

  • Fine-grained Control: Allows you to customize every aspect of the repository configuration.
  • No Dependency on Plugins: Does not require any additional plugins to be installed.

Disadvantages:

  • More Complex: Requires understanding the format of the repository configuration files.
  • Error-Prone: Manual editing can introduce errors if not done carefully.

2. Using Ansible for Repository Management:

Ansible is a powerful automation tool that can be used to manage DNF repositories across multiple systems. Using Ansible, you can define repository configurations in a declarative manner and ensure that all your systems have the correct repositories enabled and configured.

Explanation:

Ansible uses "playbooks" which are YAML files that define a series of tasks to be executed on remote hosts. For managing DNF repositories, you can use the dnf module within an Ansible playbook. This module allows you to add, remove, enable, and disable repositories.

Example:

Here’s an example of an Ansible playbook that adds a repository, enables it, and installs a package from it:

---
- hosts: all
  become: true
  tasks:
    - name: Add custom repository
      dnf:
        name: mycustomrepo
        baseurl: http://www.example.com/mycustomrepo/
        enabled: yes
        gpgcheck: no
        state: present
        repo_gpgcheck: no

    - name: Install package from custom repository
      dnf:
        name: mypackage
        state: present

This playbook first defines the mycustomrepo repository with the specified baseurl, enabled state, and GPG check settings. The state: present ensures that the repository is added if it doesn’t already exist. The second task then installs the mypackage package from the newly added repository. The option repo_gpgcheck: no is added for cases where gpgcheck is enabled globally, but not required for the specific repo.

Advantages:

  • Automation: Automates the process of managing repositories across multiple systems.
  • Idempotency: Ansible ensures that the desired state is achieved, even if the task is run multiple times.
  • Centralized Management: Allows you to manage repository configurations from a central location.

Disadvantages:

  • Requires Ansible: Requires Ansible to be installed and configured.
  • Learning Curve: Requires understanding Ansible concepts and syntax.

These alternative methods provide flexibility and scalability for managing DNF repositories, depending on your specific needs and environment. Manually editing files is suitable for single systems and advanced control, while Ansible is ideal for managing repositories across a large number of systems in an automated and consistent manner.

Leave a Reply

Your email address will not be published. Required fields are marked *