# Ansible Error : Error while linking: \[Errno 13\] Permission denied

**URL:** <https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973>\
**Category:** Ansible Project\
**Created:** [July 13, 2017, 1:27pm UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973 "2017-07-13T13:27:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![swapnil\_bendekar](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@swapnil\_bendekar](https://forum.ansible.com/u/swapnil_bendekar)\
**Post date:** [July 13, 2017, 1:27pm UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973/1 "2017-07-13T13:27:03Z")

</div>

Hello Folks,

With Ansible(2.3.0.0) and python(2.6.6), executing ansible playbook from webadmin user.  
Using remote\_user = ansible (in ansible.cfg )for passwordless authentication.  
While creating symlink, getting Error while linking: [Errno 13] Permission denied  
Syntax used:  
file:  
src: /path/to/be/linked  
dest: “{{dest\_home}}/{{dest\_app}}”  
state: link  
follow: True  
force: True

Appreciate your help to resolve this issue.

---

<div class="post-metadata">

**Author:** ![Mathias\_Ettinger](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@Mathias\_Ettinger](https://forum.ansible.com/u/Mathias_Ettinger)\
**Post date:** [July 14, 2017, 9:01am UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973/2 "2017-07-14T09:01:19Z")

</div>

Even with passwordless sudo, you may still want to use become:yes to actually invoke the command using sudo.

---

<div class="post-metadata">

**Author:** ![swapnil\_bendekar](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@swapnil\_bendekar](https://forum.ansible.com/u/swapnil_bendekar)\
**Post date:** [July 19, 2017, 7:40am UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973/3 "2017-07-19T07:40:54Z")

</div>

Thanks Mathias for your response and sorry for late reply.  
Issue still persists

“msg”: “Error while linking: [Errno 13] Permission denied”,  
“path”: “/path/to/be/linked”,  
“state”: “absent”

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 19, 2017, 9:10am UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973/4 "2017-07-19T09:10:40Z")

</div>

what does your entire playbook look like?

---

<div class="post-metadata">

**Author:** ![swapnil\_bendekar](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@swapnil\_bendekar](https://forum.ansible.com/u/swapnil_bendekar)\
**Post date:** [July 19, 2017, 9:56am UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973/5 "2017-07-19T09:56:23Z")

</div>

Thanks Dick for your response.

Actually, I have logged in as user1 (user1grp) but want to deploy using user2 (user2grp). Because passwordless authentication can be enabled for user2 and NOT for user1

Source and destination has permission as user1:user1grp

snippet of playbook look likes:

- hosts: app1  
remote\_user: user2  
vars:  
dest\_home: “/LINK/NAME”  
dest\_app: “libs/app”  
lib\_app: “app”  
sleep\_interval: 15

tasks:

- name: Link Release Deployment “{{lib\_app}}” Application  
file:  
src: /path/to/be/linked  
dest: “{{dest\_home}}/{{dest\_app}}”  
state: link  
follow: True  
force: True

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 19, 2017, 10:46am UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973/6 "2017-07-19T10:46:21Z")

</div>

The user2 account (even though it's "passwordless authentication" -  
whatever that means) doesn't have the right permissions to be able to  
create the links.

mathias.ettinger@gmail.com already gave you a hint, try that please.

Dick

---

<div class="post-metadata">

**Author:** ![swapnil\_bendekar](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@swapnil\_bendekar](https://forum.ansible.com/u/swapnil_bendekar)\
**Post date:** [July 19, 2017, 11:04am UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973/7 "2017-07-19T11:04:55Z")

</div>

Hello Dick,

user2 is already added to sudoers to allow execution of needful commands

user2 ALL=(ALL) NOPASSWD: /bin/mkdir  
user2 ALL=(ALL) NOPASSWD: /usr/bin/rsync  
user2 ALL=(ALL) NOPASSWD: /bin/ln

Tried option suggested by Mathias, but getting same error

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [July 19, 2017, 11:10am UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973/8 "2017-07-19T11:10:47Z")

</div>

Ansible modules (generally) don’t use cli commands. You have to allow execution of arbitrary commands for ansible to be able to work.

Please see here: [http://docs.ansible.com/ansible/become.html#can-t-limit-escalation-to-certain-commands](http://docs.ansible.com/ansible/become.html#can-t-limit-escalation-to-certain-commands)

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![swapnil\_bendekar](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@swapnil\_bendekar](https://forum.ansible.com/u/swapnil_bendekar)\
**Post date:** [July 19, 2017, 11:58am UTC](https://forum.ansible.com/t/ansible-error-error-while-linking-errno-13-permission-denied/24973/9 "2017-07-19T11:58:57Z")

</div>

Thanks Pshem for the information.

Initially we were getting permission denied error for mkdir and kill, but it got resolved after adding it into sudoers which is not the case with “ln”
