Sorry to be digging up an old thread. I ran into this issue to and the issue is not always simply sudo/password/-K issue.
sudo is often configured to only allow certain commands to run via sudo. For example, a developer that may restart a web service, but not administer the rest of the system. After tracing logs, I believe ansible does not support this.
For example, sudo is configured with the follow authorisation: %tomcat7 ALL=(ALL) NOPASSWD: /usr/sbin/service tomcat7 restart
User runs ‘sudo service tomcat7 restart’ in a shell directly:
==> /var/log/auth.log <==
Nov 18 18:49:46 host sudo: username : TTY=pts/0 ; PWD=/home/username ; USER=root ; COMMAND=/usr/sbin/service tomcat7 restart
Nov 18 18:49:46 host sudo: pam_unix(sudo:session): session opened for user root by username(uid=0)
Nov 18 18:49:52 host sudo: pam_unix(sudo:session): session closed for user root
Sorry to bring up this old thread again, but I’m running into the same issue as Phil.
I’d like to have a user that has sudo access to restart Apache but not, say, delete it.
How do people typically handle this? Is it possible to create users that can run ansible modules like “service” as sudo, without having sudo rights to run every command?
Or is the expectation that Ansible should have full sudo access?