Senger CodeLab πŸš€

Ansible fails with binsh 1 usrbinpython not found

September 29, 2026

πŸ“‚ Categories: Programming
🏷 Tags: Ansible
Ansible fails with binsh 1 usrbinpython not found

Encountering the error message Ansible fails with /bin/sh: 1: /usr/bin/python: not found can be a significant roadblock when automating tasks. This particular error indicates that Ansible, when attempting to execute a module on a remote host, cannot locate the Python interpreter at the expected path. Since Ansible heavily relies on Python to run its modules and manage systems, a missing or incorrectly specified Python path effectively halts your automation efforts. This guide will delve into the root causes of this common issue, provide clear, actionable steps to resolve it, and offer best practices to prevent its recurrence, ensuring your Ansible playbooks execute smoothly and reliably across your infrastructure.

Understanding the “Python Not Found” Error in Ansible

The core of Ansible’s operation relies on Python. When you run an Ansible playbook, the control node connects to your managed nodes (remote hosts) and executes small Python scripts, known as modules, to perform the desired tasks. These modules require a Python interpreter to run. The error message /bin/sh: 1: /usr/bin/python: not found specifically means that the shell on the remote host, when instructed by Ansible, could not find an executable named python at the path /usr/bin/python. This isn’t just a minor glitch; it’s a fundamental communication breakdown.

The default behavior for many Linux distributions, especially older ones, places the Python 2 interpreter at /usr/bin/python. However, modern distributions often prioritize Python 3, making /usr/bin/python3 the primary executable, or sometimes omit a direct python symlink entirely. This discrepancy between Ansible’s default expectation and the remote host’s configuration is a frequent cause of the issue. Understanding the role of the ansible_python_interpreter variable is crucial here, as it dictates which Python executable Ansible should use on a given managed node.

Without a correctly configured Python interpreter, Ansible cannot even gather basic facts about the remote host, let alone execute complex tasks like package installations or service management. This error effectively renders the remote host unreachable for Ansible’s automation capabilities, making it imperative to address this foundational dependency. Resolving this often involves checking the specific Python version and its location on the target system.

Common Culprits Behind the Missing Python Interpreter

Several factors can lead to Ansible failing to find the Python interpreter on your remote hosts. Pinpointing the exact cause is the first step towards a lasting solution. Understanding these common scenarios can significantly speed up your troubleshooting process when you encounter the Ansible fails with /bin/sh: 1: /usr/bin/python: not found error.

  • Python Not Installed: This is the most straightforward reason. Some minimal server installations might not include Python by default. Ansible needs a working Python environment to function.
  • Incorrect ansible_python_interpreter Path: Ansible’s default assumption for the Python executable path might not match the actual location on your remote host. For example, if Python 3 is at /usr/bin/python3 and Ansible expects /usr/bin/python, the error will occur.
  • python vs. python3 vs. python2 Symlinks: Many modern Linux distributions no longer have a /usr/bin/python symlink pointing to Python 2 or even Python 3 by default. They might only have /usr/bin/python3 or /usr/bin/python2.
  • PATH Environment Variable Issues: If the Python executable is installed in a non-standard location and that location isn’t included in the remote user’s PATH environment variable, the shell won’t find it.
  • Virtual Environments: While common for development, running Ansible directly against a remote host that expects a specific Python virtual environment without proper configuration can lead to interpreter path issues.
  • Permissions: Less common, but insufficient permissions for the Ansible user to access the Python executable on the remote host can also manifest as a “not found” error.

According to Ansible’s official documentation, correctly defining the ansible_python_interpreter variable is one of the most critical steps to ensure smooth execution, especially in heterogeneous environments. Neglecting this crucial configuration often leads to the exact “Python not found” error that many users struggle with, highlighting the importance of explicit environment declarations.

Step-by-Step Solutions to Resolve the Error

When faced with the “Ansible fails with /bin/sh: 1: /usr/bin/python: not found” error, a systematic approach is key. The following steps will guide you through diagnosing and fixing the issue, ensuring your Ansible playbooks can communicate effectively with your remote hosts. Many times, it’s a simple configuration tweak that makes all the difference.

  1. **Verify Python Installation on Remote Host:**First, manually connect to your remote host via SSH and check if Python is installed and where it’s located. Use commands like which python, which python3, or ls -l /usr/bin/python to find the correct path. If Python isn’t installed, you’ll need to install it. For Debian/Ubuntu, use sudo apt update && sudo apt install python3 -y. For CentOS/RHEL, use sudo yum install python3 -y or sudo dnf install python3 -y. Ensure the Python version is compatible with your Ansible control node’s requirements.

  2. **Set the ansible_python_interpreter Variable:**Once you know the correct Python path (e.g., /usr/bin/python3), instruct Ansible to use it. You can do this in your inventory file (hosts.ini or YAML) or directly in your playbook:

    In inventory (hosts.ini) [webservers] web1.example.com ansible_python_interpreter=/usr/bin/python3 In inventory (YAML) all: hosts: web1.example.com: ansible_python_interpreter: /usr/bin/python3 In a playbook (for all hosts or specific tasks) - hosts: all vars: ansible_python_interpreter: /usr/bin/python3 tasks: - name: Ensure Nginx is installed apt: name: nginx state: present 
    

    This is often the most effective solution for the Ansible fails with /bin/sh: 1: /usr/bin/python: not found error.

  3. **Use the raw Module for Initial Python Installation (If Needed):**If Python isn’t installed at all, and you can’t manually SSH to install it, you can use Ansible’s raw module as a bootstrap mechanism. The raw module doesn’t require Python on the remote host, as it executes commands directly via SSH:

    < Question & Answer :
    I’m running into an error I’ve never seen before. Here is the command and the error:

    $ ansible-playbook create_api.yml PLAY [straw] ****************************************************************** GATHERING FACTS *************************************************************** failed: [104.55.47.224] => {"failed": true, "parsed": false} /bin/sh: 1: /usr/bin/python: not found TASK: [typical | install required system packages] ***************************** FATAL: no hosts matched or all hosts have already failed -- aborting PLAY RECAP ******************************************************************** to retry, use: --limit @/Users/john/create_api.retry 104.55.47.224 : ok=0 changed=0 unreachable=0 failed=1 
    

    Here is the create_api.yml file:

    --- - hosts: api remote_user: root roles: - api 
    

    And here is the hosts file:

    [api] 104.55.47.224 
    

    I can remove the roles section and it won’t make it to the first TASK, it will instead make it will only make it to the line /bin/sh: 1: /usr/bin/python: not found. What could be going on here?


    NOTE: In case anyone is pinging the IP address and failing to get a response, you should know I’ve changed the IP address since pasting code.

    EDIT python was installed locally, the problem was that it was not installed on the remote machine, which was running Ubuntu 15.04

    I stumbled upon this error running ansible on Ubuntu 15.10 server, because it ships with Python 3.4.3 and ansible requires Python 2.

    This is how my provision.yml looks now:

    - hosts: my_app sudo: yes remote_user: root gather_facts: no pre_tasks: - name: 'install python2' raw: sudo apt-get -y install python tasks: - name: 'ensure user {{ project_name }} exists' user: name={{ project_name }} state=present 
    
    • Don’t forget the -y (says yes to all questions) option with apt-get (or raw module will get stuck silently)
    • gather_facts: no line is also critical (because we can’t gather facts without python)