Question

I'm using ansible to script running a particular command (rosdep) on a remote host. This command must be run as a regular user, not root, but occasionally prompts the user for their sudo password to gain root privileges for installing software.

Is there any way to instruct ansible to respond to those password prompts while running the remote command? I don't want to run the entire command with sudo, so the -K option doesn't work for this purpose.

Was it helpful?

Solution

Consider modifying your sudoers file so that those specific commands are allowed to run through sudo without such a password prompt.

The simplest but perhaps not the best way would be to use:

tessa    ALL=NOPASSWD: ALL

which means all commands are allowed to be run through sudo without password prompt.

A better approach would be to figure out which specific commands require sudo permissions and then add them to the sudoers file.

For example:

tessa    ALL=NOPASSWD:/usr/bin/whoami

You can ship modified /etc/sudoers file/template as part of your Ansible playbook.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top