Using apt gives error

I am trying to use a playbook with ansible.builtin.apt but I get a sudo error.
I am using a user, which is not root, that effectively uses sudo in target host.
In /etc/ansible/hosts there is the IP of host with user and password

‘’'10.1.1.102 ansible_ssh_pass=‘password’ ansible_ssh_user=‘username

Error:

fatal: [10.1.1.102]: FAILED! => {"changed": false, "msg": "'/usr/bin/apt-get upgrade --with-new-pkgs ' failed: E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)\nE: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?\n", "rc": 100, "stdout": "", "stdout_lines": []}

My playbook is like
  • name: Update all packages to their latest version
    ansible.builtin.apt:
    name: “*”
    state: latest


|

  • | - |

I am using a user, which is not root, that effectively uses sudo in target host.

What exactly does “effectively uses sudo” mean?
You have to use “become: true” for this user, and it should be able to use unrestricted sudo.
Anything else will not work.

Dick

1 Like

Thanks Dick, in which file I have to use become=true?
playbook?
/etc/ansible/hosts
ansible.cfg ?

Sorry for my bad explanation. I mean that I use this ‘username’ in my host with sudo everyday and works fine.
It’s my first week exploring Ansible.

I found the solution Two things:
Firs, obviously include become: true in the playbook


Second, ask for password in command line:
ansible-playbook playbook.yaml --ask-become-pass

1 Like

Yes thats what works in your situation :+1: