Ansible returns "Missing sudo password" error despite command is allowed

Solution Verified - Updated -

Issue

  • Ansible returns "Missing sudo password" error despite command is allowed to be run without supplying a password.

  • An ansible task is specified to run as become_user user:

    - name: Playbook
      become: true
      tasks:
        - name: Show running user
          shell: /usr/bin/whoami
          become_user: bob
    
  • The REMOTE_USER (as specified in --user) is granted privilege to run the command:

    [jane@server1] $ sudo -l
    
    User jane may run the following commands on server1:
      (bob) NOPASSWD: /usr/bin/whoami
    
  • The user is able to run the command directly without supplying a password:

    [jane@server1]$ sudo -u bob /usr/bin/whoami
    bob
    
  • However, when running the ansible playbook, Missing sudo password error is returned:

    $ ansible-playbook -u jane -i inventory play.yml 
    
    TASK [Show running user] *******************************************************
    fatal: [server1.example.com]: FAILED! => {"msg": "Missing sudo password"}
    

Environment

  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
    • sudo
    • ansible

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content