2017-05-12 83 views
2

我正在嘗試配置Vagrant和Ansible的Ubuntu。我正在與this article一起工作,並遇到如下所示的錯誤。使用Ansible的流氓配置失敗

________________________ 
< 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. 

我目錄的結構是:

vagrant-project 
├── Vagrantfile 
└── playbook.yml 

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 

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 

我使用:

  • 流浪1.9.4
  • 的VirtualBox 5.1.22
  • Ansible 2.3.0.0

它們幾乎與本文中顯示的代碼相同。你能告訴我什麼是錯的,以及如何成功地配置它?

謝謝。

+0

。在你的輸出錯誤信息,指定Python路徑: 'module_stdout「:」/ bin/sh:1:/ usr/bin/python:not found'。 –

+0

http://stackoverflow.com/questions/43678361/vagrant-ansible-provisioner-throwing-error-module-failure-when-running-playboo/43678427#43678427也差不多了 –

回答

4

正如康斯坦丁蘇沃洛夫所說,這是一個可能的重複提到的職位。要回答你的問題,當在遠程主機上執行任務時,默認情況下,除python可在/ usr/bin/python中使用外。但在Ubuntu 16.04中/usr/bin/python不可用,只有/ usr/bin/python3或/usr/bin/python3.5可用

我們可以通過兩種方式解決這個問題,

1)使用在pre_tasks部分原始模塊,開始ansible任務之前安裝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 

或者

2)使用ansible_python_interpeter變量,在這種情況下,流浪漢文件將成爲

# -*- 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 
+0

非常感謝!你的答案解決了我的問題:) – Tomoya