在 Ansible 使用 Python 3 时,可能会遇到模块无法正常工作的问题。这是由于 Ansible 尚未完成其 Python 3 支持的问题所导致的。
解决此问题的方法是使用 Python 2 运行 Ansible,请使用以下命令安装 Python 2:
sudo apt-get update
sudo apt-get install python-minimal
然后将 Ansible 强制使用 Python 2,可以在 Ansible 的配置文件 /etc/ansible/ansible.cfg
中添加以下行:
[defaults]
interpreter_python = /usr/bin/python2
这样将使 Ansible 执行时强制使用 Python 2 解释器,从而解决 Python 3 兼容性问题。