1. 更新系统软件包
首先确保你的系统是最新状态。
sudo dnf update -y
2. 安装EPEL仓库
Ansible不在默认的CentOS Stream库中,但可以通过EPEL(Extra Packages for Enterprise Linux)获得。如果你还没有安装EPEL仓库,可以使用以下命令来添加它:
sudo dnf install -y epel-release
3. 安装Ansible
可以直接通过dnf来安装Ansible:
sudo dnf install -y ansible
4. 验证安装
安装完成后,你可以验证Ansible是否正确安装,并查看已安装的版本:
ansible --version
[root@localhost ansible]# ansible --version
ansible [core 2.14.17]config file = /etc/ansible/ansible.cfgconfigured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']ansible python module location = /usr/lib/python3.9/site-packages/ansibleansible collection location = /root/.ansible/collections:/usr/share/ansible/collectionsexecutable location = /usr/bin/ansiblepython version = 3.9.21 (main, Dec 4 2024, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-2)] (/usr/bin/python3)jinja version = 3.1.2libyaml = True