6

I'm trying to provision Ubuntu with Vagrant and Ansible. I'm working with this article and hit the error shown below.

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

My directory's structure is:

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

Vagrantfile contains:

# -*- 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 contains:

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

I'm using:

  • Vagrant 1.9.4
  • VirtualBox 5.1.22
  • Ansible 2.3.0.0

They are almost the same as the codes shown in the article. Could you please tell me what is wrong and how I could provision it successfully?

Thanks.

  • There is an error message in your output: `module_stdout": "/bin/sh: 1: /usr/bin/python: not found`. – Konstantin Suvorov May 12 '17 at 10:07
  • http://stackoverflow.com/questions/43678361/vagrant-ansible-provisioner-throwing-error-module-failure-when-running-playboo/43678427#43678427 is also about the same – Frederic Henri May 12 '17 at 10:55

1 Answers1

12

As Konstantin Suvorov mentioned, it is a possible duplicate of the mentioned post. To answer your question, when ansible executes on a remote host, by default it excepts python to be available in /usr/bin/python. But in ubuntu 16.04 /usr/bin/python is not available and only /usr/bin/python3 or /usr/bin/python3.5 is available.

We can overcome this problem in two ways,

1) Install python2 using the raw module in the pre_tasks section, before starting ansible tasks, so /usr/bin/python is available. The playbook would then become

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

Or

2) Specify the python path using ansible_python_interpeter variable and in this case the vagrant file would become

# -*- 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
tux
  • 1,730
  • 1
  • 15
  • 19