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
Stuck on this Ansible error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
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’
Fixed it? Get 500 Ansible & 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.
Stuck on this? Start guided troubleshooting
Open an interactive diagnostic session with this error already loaded. Work a step-by-step plan, record what each check returns, land on a root cause, and export a clean incident summary — no account needed to start.
Did this fix your issue?
Solved it a different way?
Share the fix that worked for you — reviewed, then published to help the next engineer.
That looks like it may contain a secret (key, token, password, or connection string). Please remove it — a note with a detected secret can’t be published.
Thanks — that helps. Published notes appear after a quick review.
More Ansible prompts & error guides
Every Ansible AI prompt and troubleshooting guide, in one place.
Trending errors this week
The error guides other engineers are actually reading right now.
- 1mount: wrong fs type, bad option, bad superblock
- 2Docker 'failed to set up container networking': Fix the Bridge and IP Pool
- 3Docker 'failed to create shim task': How to Fix the containerd Runtime Error
- 4Transport endpoint is not connected
- 5modprobe: FATAL: Module not found
- 6mount: wrong fs type, bad option, bad superblock
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.