FreeKB - Resolve "There was an issue creating as requested: [Erroro 13] Permission denied"
Ansible - Resolve "There was an issue creating as requested: [Erroro 13] Permission denied"

Permission denied may be displayed when attempting to do various tasks, such as using the file module to create a directory. In this example, permission denied is returned when user john.doe attempts to create the /opt/foo directory.

PLAY [all]

TASKS [mkdir /opt/foo]
fatal: [server1.example.com]: FAILED! => {"changed": false, "msg": "There was an issue creating /opt/foo as requested: [Erroro 13] Permission denied: '/opt/foo'", "path": "/opt/foo"}

PLAY RECAP
server1.example.com   : ok=0  changed=0  unreachable=0  failed=1

 

Let's say you are attempting to create the /opt/foo directory as john.doe.

---
- hosts: all
  tasks:
    - name: mkdir /opt/foo
      file:
        path: "/opt/foo"
        state: directory
        owner: root
        group: root
        mode: '0755'

 

This could be done by setting john.doe as the ansible_user in the /etc/ansible/hosts file, like this.

ansible_user=john.doe

 

Or by setting remote_user: john.doe in the playbook, like this.

---
- hosts: all
  remote_user: john.doe
  tasks:
    - name: mkdir /opt/foo
      file:
        path: "/opt/foo"
        state: directory
        owner: root
        group: root
        mode: '0755'

 

Let's also say that only root has write access to the /opt directory on the managed node (e.g. target server), like this.

drwxr-xr-x 1 root root 4096 Sep 18 13:49

 

In this scenario, running the play will return Permission denied. This is the expected result, since john.doe does not have permission to write to the /opt directory. 

PLAY [all]

TASKS [mkdir /opt/foo]
fatal: [server1.example.com]: FAILED! => {"changed": false, "msg": "There was an issue creating /opt/foo as requested: [Erroro 13] Permission denied: '/opt/foo'", "path": "/opt/foo"}

PLAY RECAP
server1.example.com   : ok=0  changed=0  unreachable=0  failed=1

 

This can be resolved by placing become_user: root and become: yes in the task, like this. Refer to our sudo become article for more details on this.

---
- hosts: all
  tasks:
    - name: mkdir /opt/foo
      become: yes
      become_user: root
      file:
        path: "/opt/foo"
        state: directory
        owner: root
        group: root
        mode: '0755'

 

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 2bad1 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |