ubuntu - 如何修复 apt-get dist-upgrade 上的错误 400

标签 ubuntu ansible

我正在本地虚拟机上运行一个大型 ansible playbook 进行测试。我已经尝试过使用 vagrant 配置的虚拟机(使用 https://app.vagrantup.com/geerlingguy/boxes/ubuntu1604 )和使用 Ubuntu Server 16.04 手动创建的虚拟机。在这两种情况下,它经常无法运行 apt

  apt:
    upgrade: dist
    update_cache: yes

  apt:
    name: nginx
    state: present
    update_cache: yes

给出错误 400,例如:

    E: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/pool/main/j/jbigkit/libjbig0_2.1-3.1_amd64.deb  400  Bad Request [IP: 91.189.88.161 80]

我已经围绕这个主题进行了大量的谷歌搜索,但还没有得出任何结论。

我可以成功 ping 通 IP,但登录并手动运行 sudo apt-get install nginx 也失败:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libtiff5 libvpx3 libxpm4 nginx-common
  nginx-core
Suggested packages:
  libgd-tools fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed
  fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libtiff5 libvpx3 libxpm4 nginx
  nginx-common nginx-core
0 to upgrade, 13 to newly install, 0 to remove and 111 not to upgrade.
Need to get 2,858 kB of archives.
After this operation, 9,311 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libjpeg-turbo8 amd64 1.4.2-0ubuntu3.1 [111 kB]
Err:2 http://gb.archive.ubuntu.com/ubuntu xenial/main amd64 libjbig0 amd64 2.1-3.1
  400  Bad Request [IP: 91.189.88.162 80]
Get:3 http://gb.archive.ubuntu.com/ubuntu xenial/main amd64 fonts-dejavu-core all 2.35-1 [1,039 kB]
Ign:4 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main i386 fontconfig-config all 2.11.94-0ubuntu1.1
Get:5 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libfontconfig1 amd64 2.11.94-0ubuntu1.1 [131 kB]
Get:6 http://gb.archive.ubuntu.com/ubuntu xenial/main amd64 libjpeg8 amd64 8c-2ubuntu8 [2,194 B]
Get:7 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libtiff5 amd64 4.0.6-1ubuntu0.5 [149 kB]
Get:8 http://gb.archive.ubuntu.com/ubuntu xenial/main amd64 libvpx3 amd64 1.5.0-2ubuntu1 [732 kB]
Get:9 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libxpm4 amd64 1:3.5.11-1ubuntu0.16.04.1 [33.8 kB]
Get:10 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libgd3 amd64 2.1.1-4ubuntu0.16.04.10 [126 kB]
Get:11 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-common all 1.10.3-0ubuntu0.16.04.3 [26.7 kB]
Get:12 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-core amd64 1.10.3-0ubuntu0.16.04.3 [429 kB]
Get:13 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx all 1.10.3-0ubuntu0.16.04.3 [3,506 B]
Get:4 http://gb.archive.ubuntu.com/ubuntu xenial-updates/main i386 fontconfig-config all 2.11.94-0ubuntu1.1 [49.9 kB]
Fetched 2,831 kB in 0s (6,789 kB/s)
E: Failed to fetch http://gb.archive.ubuntu.com/ubuntu/pool/main/j/jbigkit/libjbig0_2.1-3.1_amd64.deb  400  Bad Request [IP: 91.189.88.162 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

根据要求:

kay@ubuntu:~$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 172.16.0.11
search company.companyname.com
kay@ubuntu:~$ cat /etc/apt/sources.list
#

# deb cdrom:[Ubuntu-Server 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)]/ xenial main restricted

#deb cdrom:[Ubuntu-Server 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)]/ xenial main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://gb.archive.ubuntu.com/ubuntu/ xenial main restricted
# deb-src http://gb.archive.ubuntu.com/ubuntu/ xenial main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://gb.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
# deb-src http://gb.archive.ubuntu.com/ubuntu/ xenial-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://gb.archive.ubuntu.com/ubuntu/ xenial universe
# deb-src http://gb.archive.ubuntu.com/ubuntu/ xenial universe
deb http://gb.archive.ubuntu.com/ubuntu/ xenial-updates universe
# deb-src http://gb.archive.ubuntu.com/ubuntu/ xenial-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://gb.archive.ubuntu.com/ubuntu/ xenial multiverse
# deb-src http://gb.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://gb.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
# deb-src http://gb.archive.ubuntu.com/ubuntu/ xenial-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://gb.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://gb.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu xenial partner
# deb-src http://archive.canonical.com/ubuntu xenial partner

deb http://security.ubuntu.com/ubuntu xenial-security main restricted
# deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
# deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse
# deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse

最佳答案

任何暂时性错误(我相信您这里有暂时性错误)都可以通过使用 until/retry 组合来解决:https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#do-until-loops

示例:

- name: Install packages
  become: true
  apt:
    name: [packages]
    update_cache: true
    cache_valid_time='{{ apt_cache_valid_time|d(3600) }}'
  register: apt_result
  retries: '{{ apt_retries }}'
  delay: 10
  until: apt_result|success
  tags:
   - apt
   - install

关于ubuntu - 如何修复 apt-get dist-upgrade 上的错误 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54826920/

相关文章:

ansible - 循环遍历 Ansible playbook 嵌套数组

git - 当 git clone 在远程服务器上工作时,无主模式下的 ansible git 任务失败

linux - 更改文件权限 Linux

python - Firebird 在特定目录中创建数据库

Ansible忽略条件

docker - 如何使用 Docker-compose 编写 Ansible 剧本

Docker 卷 : Docker Volume does not get mounted correctly on Amazon Linux

ubuntu - Hiredis 异步

ubuntu - 在 ubuntu 中安装 vagrant 吗?

eclipse - 如何在 Eclipse 中更改自动完成框中的突出显示颜色