AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible Permission Denied (Errno 13): Fix File Access Errors — Video Tutorial

Fix Ansible Permission denied [Errno 13] errors. Resolve file permission, become/sudo, SELinux, and directory access issues with troubleshooting steps.

Watch on YouTube · Read the written article

Tutorial summary

What you'll learn

  • Introduction
  • The Demo
  • Error Code
  • Error Execution
  • Fix Code
  • Fix Execution
  • Conclusion
  • Common Causes and Fixes
  • Missing become (sudo)
  • Directory doesn't exist
Introduction Welcome to another episode of Ansible Pilot! I'm Luca Berton, and today we're delving into Ansible troubleshooting, focusing on the pesky "Permission Denied Errno 13" error. Join me as we explore the intricacies of this issue, reproduce it in a live Playbook, and learn how to effectively resolve it using privilege escalation in Ansible Playbooks. The Demo Let's jump right into a live Playbook to understand how to troubleshoot the Ansible fatal error [Errno 13] Permission denied and fix it in an Ansible Playbook. Error Code ```yaml permissiondenied_error.yml --- - name: set environment Playbook hosts: all gather_facts: false vars: os_environment: - key: EDITOR value: vi tasks: - name: customize /etc/environment ansible.builtin.lineinline: dest: "/etc/environment" state: present regexp: "^{{ item.key }}=" line: "{{ item.key }}={{ item.value }}" with_items: "{{ os_environment }}" ``` Error Execution ```bash ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory troubleshooting/permissiondenied_error.yml PLAY [set environment Playbook] *********************************************************************** TASK [customize /etc/environment] ***************************************************************** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: PermissionError: [Errno 13] Permission denied: b'/home/devops/.ansible/tmp/ansible-tmp-1645543127.772594-89712-144540003805636/tmpvhoh4q83' -> b'/etc/environment' failed: [demo.example.com] (item={'key': 'EDITOR', 'value': 'vi'}) => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "ansible_loop_var": "item", "changed": false, "item": {"key": "EDITOR", "value": "vi"}, "msg": "The destination directory (/etc) is not writable by the current user. Error was: [Errno 13] Permission denied: b'/etc/.ansible_tmp_hwdwg3denvironment'"} PLAY RECAP **************************************************************************************** demo.example.com : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ansible-pilot $ ``` Fix Code ```yaml permissiondenied_fix.yml --- - name: set environment Playbook hosts: all gather_facts: false become: true vars: os_environment: - key: EDITOR value: vi tasks: - name: customize /etc/environment ansible.builtin.lineinline: dest: "/etc/environment" state: present regexp: "^{{ item.key }}=" line: "{{ item.key }}={{ item.value }}" with_items: "{{ os_environment }}" ``` Fix Execution ```bash ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory troubleshooting/permissiondenied_fix.yml PLAY [set environment Playbook] *********************************************************************** TASK [customize /etc/environment] ***************************************

About this tutorial

  • Author: Luca Berton
  • Difficulty: Beginner
  • Read time: 7 min
  • Category: installation

Topics covered

Related video tutorials