• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Ansible /bin/sh: 1: /usr/bin/python: not found

November 29, 2016 by Sharad Chhetri

Ansible which is now a days become very popular among DevOps folks. Ansible is a very simple automation tool widely use for managing the infrastructure and continuous delivery. You can install ansible in Linux system and it is agentless.

Recently after installing Ansible 2.2.1 first I encountered with this error that is “module_stdout”: “/bin/sh: 1: /usr/bin/python: not found\r\n”.

sharad@ip-172-31-7-94:~$ ansible -i inventory/staging staging -m ping
172.31.22.117 | FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Shared connection to 172.31.22.117 closed.\r\n", 
    "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", 
    "msg": "MODULE FAILURE"
}

As we know currently the ansible modules supports python 2.4, which is very well defined here in Ansible Official page –

Setting of an inventory variable ‘ansible_python_interpreter’ on any host will allow Ansible to auto-replace the interpreter used when executing python modules. Thus, you can point to any python you want on the system if /usr/bin/python on your system does not point to a Python 2.X interpreter.

Solution: To get your ansible working you have to do two things as given below.

1. Install python 2.x in remote server.

   ### In Ubuntu/Debian system
   sudo apt-get update
   sudo apt-get install python2.7

2. Set the ‘ansible_python_interpreter’ in inventory file at Ansible Server.
Given below is sample from my inventory file.

[staging:vars]
   ansible_python_interpreter=/usr/bin/python2.7

After doing above steps. All gone successfully well. Here is the result.

sharad@ip-172-31-7-94:~$ ansible -i inventory/staging staging -m ping
172.31.22.117 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. /usr/bin/env: node: No such file or directory
  2. plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
  3. Install Ansible on Ubuntu / CentOS / RHEL
  4. Install Ansible in Ubuntu 18.04 LTS with pip3
  5. Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!
  6. Can’t load ‘/usr/local/lib64/perl5/auto/nginx/nginx.so’
  7. How to list all installed python modules
  8. AttributeError: ‘WSGIRequest’ object has no attribute ‘session’ Django python web framework
  9. Remove python module installed from source code on Linux
  10. Python headers are required to build Mercurial but weren’t found

Filed Under: Linux Tagged With: ansible

Reader Interactions

Comments

  1. djoe says

    March 15, 2017 at 6:57 pm

    As the new ubuntu 16 now ships with python3, I had to do this for every host – since ansible uses python 2.7 – fixed my issue 🙂

    ansible myhost –sudo -m raw -a “apt-get install -y python2.7 python-simplejson”

    Thought I would leave it here as thanks for pointing me in the right direction, in case it helps someone else 🙂

    • Sharad Chhetri says

      March 17, 2017 at 4:50 pm

      Thank You Djoe!

  2. Ashish Singh says

    January 13, 2017 at 10:55 am

    I have tried putting the code snippet in /etc/ansible/hosts file but it says
    ”’
    ERROR! Attempted to read “/etc/ansible/hosts” as YAML: Syntax Error while loading YAML.

    The error appears to have been in ‘/etc/ansible/hosts’: line 46, column 1, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

    [servers]
    35.167.173.65
    ^ here

    Attempted to read “/etc/ansible/hosts” as ini file: /etc/ansible/hosts:15: Section [staging:vars] not valid for undefined group: staging
    ”’

    The problem is still there, I had overcome it by -e ‘ansible_python_interpreter=/usr/bin/python3’ on CLI

    • Sharad Chhetri says

      January 16, 2017 at 2:45 pm

      Hi Ashish,

      To deal with Syntax issue, setup your vim suitable to work in Ansible. For this you can install the vim plugin.
      I will recommend this plugin created by David from honneffer.com https://github.com/pearofducks/ansible-vim .
      You should also search for other YAML syntax settings in vim.

      I believe you have latest ansible 2.2 version. When you are using this new version you should use ansible_python_interpreter so that it can work with OS which has default python as version 3.x .
      As we know Ansible has lots of module which are made on the basis of python 2.x . Python 3 and Python 2 are different so Ansible team is taking time to create more module compatible with Python 3.

      I hope you have also gone through with this Ansible url https://docs.ansible.com/ansible/python_3_support.html

      Regards
      Sharad

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to empty Trash through command line in Ubuntu

How to change hostname in Ubuntu 12.04 and 12.10 without system restart

Change the default port number of ssh server

Keep logs of user after sudo su – : Secondary Logging

Password prompt in single user mode is not secure : CentOS/Red Hat

linux release renew dhcp assigned ip address

Install libjpegtran by using yum command in CentOS 6.x

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ·
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy