我有一个Vagrantfile
,它被简化为:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.boot_timeout = 900
config.vm.define 'srv' do |srv|
srv.vm.provision 'ansible' do |ansible|
ansible.compatibility_mode = '2.0'
ansible.playbook = 'playbook.yml'
end
end
end
当我运行vagrant provision
命令时,在Gathering Facts
阶段报错:/usr/bin/python: not found
,因为Ubuntu 16.04默认只安装了python3
而非Python 2.x python
。我看到有些旧文章提到这个问题。Ansible的最新版本支持使用Python 3,但必须通过在主机文件或ansible命令行中配置
ansible_python_interpreter=/usr/bin/python3
来设置。是否可以在我的Vagrantfile
或playbook.yml
文件中指定此选项?我目前没有使用主机文件,也没有通过命令行运行ansible-playbook
,而是通过Vagrant集成运行Ansible。FYI,我正在使用Ansible 2.4.1.0和Vagrant 2.0.1,它们是截至本写作时的最新版本。
extra_vars
部分中,ansible_python_interpreter: '/usr/bin/python3'
完美地运行了,谢谢! - clay/bin/sh: 1: /usr/local/opt/python@2/bin/python2.7: not found
),因此需要使用ansible.extra_vars
显式定义它以解决连接问题。我猜我在其他地方错误地设置了解释器 :/ - geerlingguyansible_python_interpreter
(参见:https://github.com/geerlingguy/ansible-role-k8s_manifests/issues/3)。 - geerlingguy