Non-zero code: 127

getting following error when building docker image

[jenkins@localhost jenkins-ansible]$ docker build -t ansible:latest .
Sending build context to Docker daemon  3.072kB
Step 1/4 : FROM jenkins/jenkins
 ---> 72d5c909f166
Step 2/4 : USER root
 ---> Running in 326240db4939
Removing intermediate container 326240db4939
 ---> e53b7e6cd21b
Step 3/4 : RUN curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py  &&     python get-pip.py &&     pip install ansible --upgrade
 ---> Running in ab53a0bfd916
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1863k  100 1863k    0     0  7454k      0 --:--:-- --:--:-- --:--:-- 7454k
/bin/sh: 1: python: not found
The command '/bin/sh -c curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py  &&     python get-pip.py &&     pip install ansible --upgrade' returned a non-zero code: 127

docker file is

FROM jenkins/jenkins

USER root

RUN curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py  && \
    python get-pip.py && \
    pip install ansible --upgrade 

USER jenkins
```

The obvious part: the command python is either not installed or in the path in the jenkins/jenkins image.

And now the fun part: Python 2.7 has reached end of life almost 2 years ago.
You might want to migrate to Python 3.7 or later, as 3.6 will reach EOL on December 23rd 2021 and all versions below already reached EOL. You will need to find a different approach to install pip, as the repo https://bootstrap.pypa.io/pip/ only provides a bootstrapping for Python versions that are EOL.

Also I would suggest to not add Ansible to the jenkins image itself, but rather add it to your build agent image. The docker agent allows to use ephemeral build containers for the pipeline execution.