Websoft9Archive / role_common

common role
Other
0 stars 5 forks source link

apt upgrade on amazon ubuntu #22

Closed qiaofeng1227 closed 2 years ago

qiaofeng1227 commented 3 years ago
TASK [role_common : Upgrade all packages to the latest version] *************************************************************************************************************************************************************************
fatal: [100.25.148.13]: FAILED! => {"changed": false, "msg": "'/usr/bin/apt-get upgrade --with-new-pkgs --auto-remove' failed: E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 9823 (apt)\nE: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?\n", "rc": 100, "stdout": "", "stdout_lines": []}
qiaofeng1227 commented 3 years ago

create a new vm on amazon ubuntu image

qiaofeng1227 commented 3 years ago

when apt install package, lock file update

root@ip-172-31-45-249:/data# apt install ansible
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ieee-data python3-argcomplete python3-crypto python3-dnspython python3-jmespath python3-kerberos python3-libcloud python3-lockfile python3-netaddr python3-ntlm-auth python3-requests-kerberos python3-requests-ntlm python3-selinux
  python3-winrm python3-xmltodict

image

qiaofeng1227 commented 3 years ago

image

qiaofeng1227 commented 3 years ago

https://docs.ansible.com/ansible/2.9/modules/apt_module.html#apt-module

qiaofeng1227 commented 3 years ago

the same issure refer to:(2019 to nowe , stilll opening) https://github.com/ansible/ansible/issues/51663 https://github.com/ansible/ansible/pull/74095

qiaofeng1227 commented 3 years ago

https://help.ubuntu.com/community/AptGet/Howto?_ga=2.186481321.1678583165.1625725961-2097582002.1625725961

chendelin1982 commented 2 years ago

What reason make apt file locked?

install.sh file have many package to install, especially apt install ansible need more time 50s

final solution

- name: Upgrade all packages to the latest version for production
  apt:
    name: "*"
    state: latest
    only_upgrade: yes
  register: result
  until: result.msg.find("Could not get lock /var/lib/dpkg") == -1  
  retries: 50
  delay: 10
  failed_when: "'FAILED' in result.stdout"
  when: common_system_upgrade and (init == '1' or init == 1)

why this solution?

try it and wait for unlocked

  1. until = while
  2. retry 50 times and delay 10s every time, nearly 500s (6 mins)