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

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.

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

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”

what does your entire playbook look like?

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

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

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

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

kind regards
Pshem

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”