I tried and it worked, obviously, because the task is actually run with root (instead of my user with sudo access) which is not what I wanted.
That’s why I’m using “become_user” (equivalent of the now deprecated “sudo_user”), in order to use sudo with my user and not root.
Below the Ansible output :
$ ansible-playbook -K -i test site.yml -vvvv
SUDO password:
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
<[the server name]> ESTABLISH CONNECTION FOR USER: [the user name]
<[the server name]> REMOTE_MODULE setup
<[the server name]> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/kevin/.ansible/cp/ansible-ssh-%h-%p-%r” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=[the user name] -o ConnectTimeout=10 [the server name] /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445011786.98-96385272343300 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1445011786.98-96385272343300 && echo $HOME/.ansible/tmp/ansible-tmp-1445011786.98-96385272343300’
<[the server name]> PUT /tmp/tmpzsyZR5 TO /home/[the user name]/.ansible/tmp/ansible-tmp-1445011786.98-96385272343300/setup
<[the server name]> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/kevin/.ansible/cp/ansible-ssh-%h-%p-%r” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=[the user name] -o ConnectTimeout=10 [the server name] /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=xlkvnygczvuuuxouqlysjwveacqafobo] password: " -u root /bin/sh -c '”’“‘echo BECOME-SUCCESS-xlkvnygczvuuuxouqlysjwveacqafobo; LANG=C LC_CTYPE=C /usr/bin/python /home/[the user name]/.ansible/tmp/ansible-tmp-1445011786.98-96385272343300/setup; rm -rf /home/[the user name]/.ansible/tmp/ansible-tmp-1445011786.98-96385272343300/ >/dev/null 2>&1’”‘"’’
ok: [[the server name]]
TASK: [Install useful system tools] *******************************************
<[the server name]> ESTABLISH CONNECTION FOR USER: [the user name]
<[the server name]> REMOTE_MODULE apt name=vim,nano,htop,git,subversion,tig,ncdu,nodejs-legacy,npm,mesa-utils state=present
<[the server name]> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/kevin/.ansible/cp/ansible-ssh-%h-%p-%r” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=[the user name] -o ConnectTimeout=10 [the server name] /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445011796.4-117959804841916 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1445011796.4-117959804841916 && echo $HOME/.ansible/tmp/ansible-tmp-1445011796.4-117959804841916’
<[the server name]> PUT /tmp/tmpDRxOC1 TO /home/[the user name]/.ansible/tmp/ansible-tmp-1445011796.4-117959804841916/apt
<[the server name]> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/kevin/.ansible/cp/ansible-ssh-%h-%p-%r” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=[the user name] -o ConnectTimeout=10 [the server name] /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=zkgarkbubgpvcowmyibknwzfzyeoksnf] password: " -u root /bin/sh -c '”’“‘echo BECOME-SUCCESS-zkgarkbubgpvcowmyibknwzfzyeoksnf; LANG=C LC_CTYPE=C /usr/bin/python /home/[the user name]/.ansible/tmp/ansible-tmp-1445011796.4-117959804841916/apt; rm -rf /home/[the user name]/.ansible/tmp/ansible-tmp-1445011796.4-117959804841916/ >/dev/null 2>&1’”‘"’’
changed: [[the server name]] =>