我正在尝试使用Vagrant和Ansible来配置Ubuntu.我正在处理这篇文章并点击下面显示的错误.
________________________
< TASK [Gathering Facts] >
------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
fatal: [default]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to 127.0.0.1 closed.\r\n", "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", "msg": "MODULE FAILURE", "rc": 0}
to retry, use: --limit @/Users/tomoya/vagrant-project/playbook.retry
____________
< PLAY RECAP >
------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
default : ok=0 changed=0 unreachable=0 failed=1
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
Run Code Online (Sandbox Code Playgroud)
我的目录结构是:
vagrant-project
??? Vagrantfile
??? playbook.yml
Run Code Online (Sandbox Code Playgroud)
Vagrantfile 包含:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provision :ansible do |ansible|
ansible.playbook = "playbook.yml"
end
end
Run Code Online (Sandbox Code Playgroud)
playbook.yml 包含:
---
- hosts: all
sudo: true
tasks:
- name: update apt cache
apt: update_cache=yes
- name: install apache
apt: name=apache2 state=present
- name: install mysql
apt: name=mysql-server state=present
- name: install php
apt: name=php5 state=present
Run Code Online (Sandbox Code Playgroud)
我正在使用:
它们几乎与文章中显示的代码相同.你能告诉我有什么问题吗?我怎样才能成功配置它?
谢谢.
tux*_*tux 12
正如Konstantin Suvorov所说,这可能与上述帖子重复.要回答你的问题,当ansible在远程主机上执行时,默认情况下它除了python在/ usr/bin/python中可用.但是在ubuntu 16.04 / usr/bin/python中不可用,只有/ usr/bin/python3或/usr/bin/python3.5可用.
我们可以通过两种方式解决这个问题,
1)在启动ansible任务之前,使用pre_tasks部分中的raw模块安装python2,这样/ usr/bin/python就可用了.然后剧本就会成为
---
- hosts: all
sudo: true
gather_facts: False
pre_tasks:
- raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
- setup:
tasks:
- name: update apt cache
apt: update_cache=yes
- name: install apache
apt: name=apache2 state=present
- name: install mysql
apt: name=mysql-server state=present
- name: install php
apt: name=php5 state=present
Run Code Online (Sandbox Code Playgroud)
要么
2)使用ansible_python_interpeter变量指定python路径,在这种情况下,变形文件将变为
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vbguest.auto_update = false
config.vm.provision :ansible do |ansible|
ansible.playbook = "playbook.yml"
ansible.extra_vars = {
ansible_python_interpreter: "/usr/bin/python3.5",
}
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1580 次 |
| 最近记录: |