How to fix missing Python for Ansible in Fedora Vagrant

Recently, I started to use Vagrant to test Ansible playbooks on Fedora machines. I’m using the Fedora 28 cloud base image. However, when I tried to provision my Vagrant box, I was warned the Python binary is missing.

$ vagrant provision
==> default: Running provisioner: ansible...
    default: Running ansible-playbook...

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [default]: FAILED! => {"changed": false, "module_stderr": "Shared connection to closed.\r\n", "module_stdout": "\r\n/bin/sh: /usr/bin/python: No such file or directory\r\n", "msg": "MODULE FAILURE", "rc": 127}
	to retry, use: --limit @playbook.retry

Problem: Python 3 by default

This error appears because Fedora 28 does not provide a Python 2 binary by default. Only Python 3 is provided on the base cloud image. I verified this by SSHing into the Vagrant box.

[[email protected] vagrant]$ vagrant ssh
[[email protected] ~]$ dnf list installed | grep -i python

Annoyingly, I must install Python 2 manually in the box each time it fails to provision. Surely, there is an easier way? Fortunately, StackOverflow came to the rescue.

Solution: ansible.extra_vars

It’s possible to tell Vagrant where the Python binary is located. You can pass the path to the python3 binary manually in your Vagrantfile.

# Provisioning configuration for Ansible.
config.vm.provision :ansible do |ansible|
  ansible.playbook = "playbook.yml"
  ansible.extra_vars = { ansible_python_interpreter:"/usr/bin/python3" }

Adding these changes to your Vagrantfile allows Ansible to successfully run on the Fedora Vagrant guest. Python is successfully located.

This is an annoying workaround, but it solves the issue and lets you successfully test and iterate changes on Fedora systems. Here’s hoping the Fedora cloud image maintainers add a default binary for /usr/bin/python to point to /usr/bin/python3 in the future.


  1. This `Fedora cloud image maintainers add a default binary for /usr/bin/python to point to /usr/bin/python3 in the future.` is the wrong solution. If Ansible is compatible with python3, it should try python3 by default. “python” is reserved for python2 according to python.

    If the Fedora maintainers adopted your solution, it would break when installing python2.

  2. Ansible is compatible with both py2 and py3 and because is a configuration management tool it will have to be compatible for a good number of years even after the 2020, as there are lots of embedded systems that will never have python interpreter upgraded.

    Also the fact that a user would have to add extra configuration to specify the interpreter based on the OS-version mixed of the “controlled decide” seems more like a hack to me than a solution.

    This is why I raised which asks for having a symlink from python to python3 on Fedora when there is only one interpreter installed. This should apply to Fedora 27 and newer. If you agree with this please express your support on the bug, even if at this moment is closed (this may chance fast based on the community feedback).

Drop a line

%d bloggers like this: