What Command Would Test If sudo Was Working without Making Any Changes?

Problem scenario
To see if Ansible can run commands with sudo without being prompted, you want to run a test.

You want to see if sudo works for certain on your Linux server.  But you do not want to destroy anything or change any files.  What should you do for a test that would tell you if sudo is working or not?

Solution
Run a command such as this:  sudo ls /root

The above would not ordinarily work for a regular Linux user.  

If you have Ansible installed and configured with an inventory (e.g., /etc/ansible/hosts) file that is ready, you can run a command like this to see if you are prompted for a password when elevating to sudo:

ansible -m shell -a 'sudo ls /root' all

If you want to test a specific managed node, you could modify the command above by replacing "all" with the hostname of the managed node you want to test.

Leave a comment

Your email address will not be published. Required fields are marked *