如何安装ansible

在讲解如何安装ansible之前,建议先了解一下ansible的基本术语,如Control Nodes, Managed Nodes, Playbook等等,具体可以参考Ansible Playbook基本介绍
所以如果你了解ansible的基本术语,你就应该知道这里所说的ansible安装,是指在Control Nodes上安装ansible软件。

Ansible是通过python编写的,所以在安装ansible之前我们得先检查当前机器已经安装了python,同时需要是python3.8以上的版本。python安装可以参考python安装

现在我们可以开始ansible的安装了,注意ansible只能安装在macos或者linux机器上,不能安装在windows机器上。

Ansible版本介绍

Ansible有两个版本可以安装:

版本详细介绍
社区版本这个版本包括ansible语言(language),运行时环境(runtime)和大量的社区贡献的Collections
ansible-core版本这个版本包括ansible语言(language),运行时环境(runtime)和少量核心模块(modules)和插件(plugin),这些都是ansible正常运行所需的最小的资源

Ansible安装

社区版本安装

pip安装

python2.x版本: python -m pip install --user ansible
python3.x版本: python3 -m pip install -user ansible

使用操作系统包管理安装
centos: sodu yum install epel-release
               sodu yum install ansible
ubuntu: sudo apt-get install ansible

Ansible-core版本安装

pip安装

python2.x版本: python -m pip install --user ansible-core
python3.x版本:python3 -m pip install --user ansible-core

源码安装

python2.x:
python -m pip install --user https://github.com/ansible/ansible/archive/devel.tar.gz
python3.x
python3 -m pip install --user https://github.com/ansible/ansible/archive/devel.tar.gz

检查ansible安装成功

运行命令: ansible all -m ping --ask-pass
如果出现类似下面画面,则说明ansible安装成功
在这里插入图片描述


版权声明:本文为qinwuxian19891211原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。