In this article I will show you how to activate the EPEL deposit under CentOS with Ansible. Okay, let’s get started.
Activation of the EPEL repository on computers equipped with CentOS 7 or CentOS 8 with Ansible :
- You must have Ansible installed on your computer.
- CentOS 7 or CentOS 8 machines must be configured for possible automation.
There are many articles on LinuxHint that deal with installing Ansible and configuring hosts for automation. If necessary, you can read these articles for your own purposes.
Enabling EPEL deposit on CentOS hosts Why not try here Linux Server Support.
First create the project folder ~/project with the following command :
$ mkdir -pv ~/Project/Gamebook
Use the following command to go to the ~/project directory
Create new file nodes in the project directory and open them in the nanotexte editor as follows
Empty file hosts must be created and opened with the Nano word processor.
Enter the IP addresses or DNS names of the target CentOS 7 and CentOS 8 computers (on which you want to enable the EPEL repository) into the centos hosts section as follows
Here, 192.168.20.169 is the IP address of my CentOS 8 virtual machine, and 192.168.20.222 is the IP address of my CentOS 7 virtual machine. It’ll be different with you. Make sure that the example IP address is now replaced by your own list.
NOTE : You can determine the IP addresses of your CentOS hosts using the following command:
If you have configured DNS names on your CentOS hosts, you can find them using the following command:
The last host file should look like the one shown in the following screenshot.
Now save the host file by pressing + X, then Y and .
Create the configuration file ansible.cfg as follows
Enter the following lines in the ansible.cfg file:
After this step, save the file by pressing + X, then Y and .
Now create a new playbook allow_epel_repo.yaml in the playbooks/ as shown below :
$ nano playbooks/enable_epel_repo.yaml
Then enter the following codes into the enable_epel_repo.yaml file:
– Host: centos
User: permitted tasks
– Name: Activate the EPEL repository on CentOS 8
dnf : Name
Status : becomes the last
if: Allowable Facts[‘os_family’] == RedHat and Allowable Facts
[‘distribution_major_version’] == 8
– name : Activate the EPEL repository on CentOS 7
Name : epel-release
Status : becomes the last
if: ansible_facts[‘os_family’] == RedHat and ansible_facts
[‘distribution_major_version’] == 7.
In this code:
hosts: centos, selects in the hosts file only the hosts that are part of the centos group.
User: asible, the SSH hostname (where Ansible will perform the tasks) will be available.
I’ve defined two tasks here. One for CentOS-8 hosts and one for CentOS-7 hosts. The reason I did this is because the default package manager for CentOS is DNF for CentOS 8 and YUM for CentOS 7. One task (first task) uses the DNF packet manager and runs only on CentOS 8 hosts. Another task (the last one) uses the YUM packet manager and only works on CentOS 7 hosts.
These two tasks are almost identical. The only differences are the package management modules (dnf and yum) used in the tasks and the code for checking CentOS versions.
dnf and yum Authorized modules accept the same parameters.
Here’s the name: epel-release, the package to install is epel-release.
Condition: Finally, the spelling version of the package must be installed. If a package is already installed and an updated version is available, the package will be updated.
when: the condition, if the condition is true, then the task is completed otherwise the task will not be completed.
ansible_facts, which are used to access ansible host variables.
Ansible_facts[‘os_family’] == ‘RedHat’, checks whether the host operating system is CentOS or RedHat.
Ansible_facts[‘distribution_major_version’] == ‘8’, checks if version 8 of the host operating system (in this case CentOS 8 or RedHat 8) is installed.
Ansible_facts[‘distribution_major_version’] == ‘7’, checks if the host operating system is version 7 (in this case, CentOS 7 or RedHat 7).
Then save the enable_epel_repo.yaml file by pressing + X, then Y and .
You can now run the Ansible playbook as follows:
$ asible-playbook game books/enable_epel_repo.yaml
The script must work properly and the EPEL repository must be enabled on both CentOS 7 and CentOS 8.
As you can see, the EPEL deposit is enabled on my host, CentOS 8.
As you can see, the EPEL deposit is enabled on my host, CentOS 7.
Here is how to activate the EPEL deposit on CentOS with Ansible. Thank you for reading this article.download epel repo for centos 7 offline,epel repo centos 7,install ansible centos 8,install ansible centos 7,epel ansible,install ansible on rhel 7,error getting repository data for epel, repository not found,install ansible centos 7 pip