Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and use on CentOS 8 and RHEL 8 systems

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Ansible is an excellent automation tool for Linux system administrators. It is an open source configuration tool that allows system administrators to manage hundreds of servers from a central node, the Ansible server. When comparing Ansible with similar tools such as Puppet, Chef, and Salt, it is the preferred configuration tool because it does not require any agents and works on SSH and python.

In this tutorial, we will learn how to install and use Ansble on CentOS 8 and RHEL 8 systems.

Ansible lab environment information:

Minimize installed CentOS 8 / RHEL 8 server (192.168.1.10) with Internet connection

Two Ansible nodes-Ubuntu 18.04 LTS (192.168.1.20) and CentOS 7 (192.168.1.30)

Ansible installation steps on CentOS 8

The Ansible package is not in the default package repository for CentOS 8. Therefore, we need to execute the following command to enable the EPEL repository:

[root@linuxtechi ~] $sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm-y

After enabling the epel warehouse, execute the following dnf command to install Ansible:

[root@linuxtechi ~] $sudo dnf install ansible

The output of the above command:

Dnf-install-ansible-centos8

After successfully installing Ansible, run the following command to verify its version:

[root@linuxtechi] $sudo ansible-- version

Ansible-version-CentOS8

The above output confirms that the installation is complete on CentOS 8.

Let's look at the RHEL 8 system.

Ansible installation steps on RHEL 8

If you have a valid RHEL 8 subscription, use the following subscription manager command to enable the Ansble repository:

[root@linuxtechi] $sudo subscription-manager repos-- enable ansible-2.8-for-rhel-8-x86_64-rpms

After enabling the warehouse, execute the following dnf command to install Ansible:

[root@linuxtechi] $sudo dnf install ansible-y

After installing Ansible and its dependent packages, execute the following command to verify its version:

[root@linuxtechi] $sudo ansible-- version

Optional method of installing Ansible through pip3 on CentOS 8 / RHEL 8

If you want to install Ansible using pip (Python's package manager), first install the pyhton3 and python3-pip packages using the following command:

[root@linuxtechi] $sudo dnf install python3 python3-pip-y

After installing python3, run the following command to verify its version:

[root@linuxtechi ~] $python3-VPython 3.6.8 [root@linuxtechi ~] $

Install Ansible with the following pip3 command:

[root@linuxtechi] $pip3 install ansible-- user

Output:

Ansible-Install-pip3-centos8

The above output confirms that Ansible has been successfully installed using pip3. Let's take a look at how to use Ansible.

How do I use Ansible automation tools?

When we install Ansible using the yum or dnf command, its configuration files, manifest files, and role directories are automatically created under the / etc/ansible folder.

Let's add a group named labservers and add the IP address of the above Ubuntu 18.04 and CentOS 7 systems to the group in the / etc/ansible/hosts file:

[root@linuxtechi] $sudo vi / etc/ansible/hosts... [labservers] 192.168.1.20192.168.1.30...

Save and exit the file.

After updating the manifest file (/ etc/ansible/hosts), place the user's ssh public key on a remote system that belongs to the labservers group.

Let's first use the ssh-keygen command to generate the public and private keys of the local user:

[root@linuxtechi ~] $ssh-keygen

Now use the following command to exchange public keys between the Ansible server and its clients:

[root@linuxtechi ~] $ssh-copy-id root@linuxtechi [root@linuxtechi ~] $ssh-copy-id root@linuxtechi

Now, let's try a few Ansible commands, first using the ping module to verify the connection between the Ansible server and the client:

[root@linuxtechi ~] $ansible-m ping "labservers"

Note: if we do not specify the manifest file in the above command, it will reference the default host file (that is, / etc/ansible/hosts).

Output:

Ansible-ping-module-centos8

Let's use the Ansible shell command to check the kernel version of each client:

[root@linuxtechi ~] $ansible-m command-a "uname-r"labservers" 192.168.1.30 | CHANGED | rc=0 > > 4.15.0-20-generic192.168.1.20 | CHANGED | rc=0 > > 3.10.0-327.el7.x86_64 [root@linuxtechi ~] $

Use the following command to list all hosts in the manifest file:

[root@linuxtechi] $ansible all-I / etc/ansible/hosts-- list-hostshosts (4): 192.168.100.1192.168.100.10192.168.1.20192.168.1.30 [root@linuxtechi ~] $

Use the following Ansible command to list only the hosts in the labservers group:

Root@linuxtechi ~] $ansible labservers-I / etc/ansible/hosts-- list-hostshosts (2): 192.168.1.20192.168.1.30 [root@linuxtechi] $

That's all for this article, and we have successfully demonstrated how to install and use Ansible on CentOS 8 and RHEL 8 systems. Please share your feedback and opinions.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report