Introduction
Ansible is a tool for deploying a group of remote hosts. It achieves communication between the management node and remote nodes through the SSH protocol. Theoretically, any operation that can be performed by logging into a remote host via SSH can be automated in bulk using Ansible. This includes tasks such as copying files, installing packages, and initiating services. Ansible addresses the challenge of automating system configuration, application deployment, command execution, and service operations on a large scale. Its scripts are flexible and reentrant, significantly reducing repetitive tasks for operations personnel and improving operational efficiency.
SSH must be configured for public key authentication, not password authentication.
Ansible Tower is a paid software for enterprise users that provides a web interface for administrators to run Ansible script Playbooks.
Environment Planning
| Host Name | IP Address | Role | Operating System |
|---|---|---|---|
| ansible | 192.168.0.51 | Ansible Management Node | Rocky Linux |
Basic Configuration
Installing Ansible
# Install EPEL repository and Ansible
[root@ansible ~]# sudo yum install epel-release
[root@ansible ~]# sudo yum install ansible -y
# Verify
[root@ansible ~]# ansible --version
Configuring Connection Between Ansible Management Node and Hosts
# Generate SSH key
[root@ansible ~]# ssh-keygen
# Copy SSH key to remote host
[root@ansible ~]# ssh-copy-id [email protected]
# Prevent prompt for saving key during SSH connection
[root@ansible ~]# ssh-keyscan 192.168.0.52 >> ~/.ssh/known_hosts
# Verify
[root@ansible ~]# ssh [email protected]