准备工作
运行 Ansible 的服务器必须且只需要安装有 Python 2.7+ 或者 Python 3.5+。
同样,受管机需要有 Python 2.6+ 或 Python 3.5以上的环境。
注意:默认情况下 Ansible 使用 /usr/bin/python 下的Python 解释器运行命令。 但部分 Linux 发行版可能只安装了 Python 3 解释器,可以从 /usr/bin/python3 找到。
可以通过inventory文件(主机清单)指定python解释器:
freebsd_host ansible_python_interpreter=/usr/local/bin/python
也可以干脆安装一个 Python 2的解释器。如果 Python 2 的解释器没有安装在指定目录 /usr/bin/python 。也需要使用修改inventory方法来指定解释器的位置。
ubuntu安装Ansible
在ubuntu中配置 PPA 来安装:
sudo apt update -ysudo apt install software-properties-common -ysudo apt-add-repository --yes --update ppa:ansible/ansiblesudo apt install ansible -y
查看Ansible版本:ansible --version
