Ansible Error: 'Failed to find required executable git in paths' — Cause, Fix, and Troubleshooting Guide
Fix Ansible git module 'Failed to find required executable git in paths' error: install git on the target or fix PATH for the become user.
- #ansible
- #troubleshooting
- #automation
- #modules
Fixing errors like this? Get 500 free DevOps AI prompts
500 copy-paste AI prompts for the stack you actually run — one PDF, free.
Overview
Several modules shell out to an external binary on the target host — the git module needs git, unarchive needs tar/unzip, pip needs pip. When the binary is not installed or not on the resolved PATH, the module fails:
fatal: [web-01]: FAILED! => {"changed": false, "msg": "Failed to find required executable \"git\" in paths: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}
The message lists the exact PATH that was searched, which is the key diagnostic.
Symptoms
- The
git(orpip,svn,make) task fails on a minimal host. gitis installed but only found in an interactive shell, not under Ansible.- Works for one user but fails when running as a different
become_user.
ansible web-01 -i inventory.ini -b -m git -a 'repo=https://github.com/acme/app.git dest=/opt/app'
web-01 | FAILED! => {"msg": "Failed to find required executable \"git\" in paths: /usr/bin:/bin"}
Common Root Causes
1. git is simply not installed
The most common case on slim base images and containers.
2. Installed outside the searched PATH
git lives in /usr/local/bin or /opt/.../bin, but Ansible’s non-login shell PATH does not include it.
3. PATH differs for the become user
root’s or the service user’s PATH is narrower than your interactive login shell’s.
4. Package name mismatch
Installing the wrong package name for the distro (git-core vs git).
How to diagnose
Check whether the binary exists and where:
ansible web-01 -i inventory.ini -b -m shell -a 'command -v git; echo "PATH=$PATH"'
Compare interactive vs non-interactive PATH:
ansible web-01 -i inventory.ini -b -m shell -a 'bash -lc "command -v git"'
Fixes
Install git before the git task
- name: Ensure git is installed
ansible.builtin.package:
name: git
state: present
- name: Clone the app repo
ansible.builtin.git:
repo: https://github.com/acme/app.git
dest: /opt/app
version: main
Point the module at the binary’s real location
Set PATH for the task’s environment:
- name: Clone with extended PATH
ansible.builtin.git:
repo: https://github.com/acme/app.git
dest: /opt/app
environment:
PATH: "/usr/local/bin:{{ ansible_env.PATH }}"
Symlink into a standard path (last resort)
ansible web-01 -i inventory.ini -b -m file -a "src=/opt/tools/bin/git dest=/usr/local/bin/git state=link"
What to watch out for
- Ansible uses a non-login shell, so
~/.bashrc/~/.profilePATH tweaks do not apply — set PATH via the module’senvironmentor install to a standard location. - Order dependencies explicitly: the install task must run before the module that needs the binary.
- The
PATH:value in the error is exactly what was searched — compare it againstcommand -v giton the host to pinpoint the gap.
Related
- Ansible Error: command not found / No such file or directory
- Ansible Error: ‘unarchive Failed to find handler’
- Ansible Error: ‘No package matching found available’
More Ansible prompts & error guides
Every Ansible AI prompt and troubleshooting guide, in one place.
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.