On my server, I have a sudoer user granted to only run chown in passwordless mode.
so, when I run
sudo chown mytargetuser:mytargetgroup /my/path
it works. However when I try to do the same in an Ansible playbook :
tasks:
- name: change folder ownership
become: yes
become_user: root
become_method: sudo
file:
path: "/my/path"
owner: mytargetuser
group: mytargetgroup
Ansible returns this error :
FAILED! => {"changed": false, "module_stderr": "", "module_stdout": "sudo: a password is required\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
when using directly the shell module works too:
- name: test via script
shell : sudo chown mytargetuser:mytargetgroup /my/path
Is there an integrated way to include this behaviour in a playbook or should I remain with my last solution using the shell plugin ?
Regards,
Christophe