Ansible - Failed to lock apt for exclusive operation


#1

Hello,

I have been facing some issue and i got throw it but i got stuck on the error below once it complaing i didnt get well.

I believe it is a user permission issue, but if i insert sudo on my yml file it will get a error because it prompt a password.

Should i turn off to prompt the password for the root? isnt there any other solution?

weslley@weslley:~/Desktop$ ansible-playbook nginx.yml

PLAY [servers] *****************************************************************

TASK [setup] *******************************************************************
ok: [ubuntu_server]

TASK [Install nginx web server] ************************************************
fatal: [ubuntu_server]: FAILED! => {“changed”: false, “failed”: true, “msg”: “Failed to lock apt for exclusive operation”}

NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @nginx.retry

PLAY RECAP *********************************************************************
ubuntu_server : ok=1 changed=0 unreachable=0 failed=1


#2

Ok… The best thing i found out to make it work you find below:

::: Inserted sudo: yes


  • hosts: servers
    sudo: yes
    #remote_user: root
    #become: true
    #become_user: root

    tasks:

    • name: Install nginx web server
      apt: pkg=nginx state=installed update_cache=true
      notify:
      • start nginx
        handlers:
    • name: start nginx
      service: name=nginx state=started

:::::: Turned off ubuntu from asking the password to get as root .

Is there any safer solution??

Regards