如何在 Fedora 35 上安装 Ansible

Linux命令3年前 (2022)发布 AI观察员
162 0 0

Ansible 是一个开源软件供应、配置管理和应用程序部署工具,支持基础设施即代码。Ansible 自动化并简化了重复、复杂和乏味的操作。这是一个用 Python 编写的免费工具。如何在 Fedora 35 上安装 Ansible

Fedora 35安装 Ansible

第 1 步:在继续之前,更新您的 Fedora 操作系统以确保所有现有的软件包都是最新的。使用此命令更新服务器包:

sudo dnf upgrade
sudo dnf update

步骤 2. 安装 Python。

Ansible 是用 Python 编写的,现在我们使用以下命令在 Fedora 系统上安装 Python :

sudo dnf install python3
sudo dnf install python3-pip

步骤 3. 在 Fedora 35 上安装 Ansible。

默认情况下,Ansible 在 Fedora 35 基础存储库中可用。现在运行以下命令来安装它:

sudo dnf install ansible

我们可以通过运行以下命令来验证 Ansible 版本:

ansible --version

输出:

ansible 2.9.30
  config file =/etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location =/usr/lib/python3.8/site-packages/ansible executable location =/usr/bin/ansible python version =3.9.8 (default, Dec 10 2021, 00:11:01) [GCC 10.2.1 20200723 (Red Hat 10.2.1-1)]

第 4 步:测试 Ansible。

现在我们使用Fedora 上的命令创建密钥对:ssh-keygen

ssh-keygen

输出:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/idroot/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/idroot/.ssh/id_rsa.
Your public key has been saved in /home/idroot/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:vRdPlegZg1meilana0jQsiTYmariaSnuUQj3g fedora@ip-10-2-40-54.us-east-4.compute.internal
The key's randomart image is:
+---[RSA 3072]----+
|           oo  . |
|         o.ooo+ o|
|        .o+*O=o*.|
|        ooE**=B..|
|        S++X+=o. |
|          =+.=o..|
|          . . o..|
|           .     |
|                 |
+----[SHA256]-----+

接下来,将 id 复制到远程服务器:

ssh-copy-id fedora@192.168.77.21

之后,在控制机器上创建如下清单文件:

nano hosts

添加以下文件:

192.168.77.21 ansible_ssh_user=fedora

最后,使用 ping 模块测试 ansible:

ansible  -i hosts 192.168.77.21 -m ping

输出:

192.168.77.21 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

感谢您使用本教程在 Fedora 35 系统上安装 Ansible 自动化工具。如需其他帮助或有用信息,我们建议您查看Ansible 官方网站

© 版权声明

相关文章

天猫U特购  京东优惠购        京东优惠    天猫优惠