Ansible: Permission denied
Fix Ansible permission denied errors caused by missing become/sudo configuration on target hosts.
Ansible: Permission denied
Ansible reports "Permission denied" when a task requires sudo privileges but
become: trueis not set or sudo is not configured.
When Ansible Produces This Error
Ansible displays
fatal: [hostname]: FAILED! => {"msg": "Missing sudo password"} or the remote command returns
Permission denied.
What Causes Permission Denied in Ansible
The playbook runs tasks as a non-root user without
become: true. The user has
become: true set but the target system requires a sudo password and none was provided. The user is not in the
sudo group on the target.
How to Fix Permission Denied in Ansible
Add
become: trueto the play or task:- name: Install package apt: name: nginx state: present become: trueProvide the sudo password at runtime:
ansible-playbook site.yml --ask-become-passVerify the user has sudo access on the target:
ssh user@hostname 'sudo whoami'
How to Verify the Fix
Run the playbook — tasks requiring root should show
changed or
ok without permission errors.