sudo permissions with apt module

Hi,

I am trying to use apt module for installing multiple packages on my remote host. My user is not in sudoers list. However, I do have permissions to run following commands on remote host

sudo apt-get update
sudo apt-get install top

Now when I am trying to achieve same using ansible playbook, I am getting following error -

FAILED! => {“failed”: true, “msg”: “Missing sudo password”}

Following is my task definition

  • name: install basic packages
    apt: name={{item}} update_cache=yes
    become: yes
    become_method: sudo
    with_items:
  • tree
  • nload
  • htop

I have tried removing become and become_method. Then I am getting standard dpkg lock error with -vvv flag -
Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)\nE: Unable to lock the administration directory (/var/lib/dpkg/), are you root?\n

What could be potential issue here ?

ansible is not using those commands and will not work with restricted sudo in that way, it needs full sudo to accomplish these tasks. Most of the work of the apt module is using the apt-python API.

So either change your permissions on the system or use the shell or
command modules instead of the apt module. I would go for the first one...

Regards,
Johannes