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 Ansible for CentOS8 and RHEL8

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "CentOS8 and RHEL8 how to install Ansible", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "CentOS8 and RHEL8 how to install Ansible" bar!

Ansible is a new automatic operation and maintenance tool. Based on Python development, it integrates the advantages of many operation and maintenance tools (puppet, chef, func, fabric), and realizes the functions of batch system configuration, batch program deployment, batch running commands and so on.

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-- optional method for version to install 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 ~] $Thank you for reading. The above is the content of "how to install Ansible for CentOS8 and RHEL8". After the study of this article, I believe you have a deeper understanding of how CentOS8 and RHEL8 install Ansible, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Development

Wechat

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

12
Report