我正在本地VM上运行一个大型ansible剧本以进行测试。我已经尝试了使用由vagrant提供的VM(使用https://app.vagrantup.com/geerlingguy/boxes/ubuntu1604)和使用Ubuntu Server 16.04手动创建的VM。在这两种情况下,在运行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
答案 0 :(得分:1)
我认为这不是与ansible
相关的问题,而是网络/防火墙问题。
您要回答的问题:
91.189.88.161
?似乎resolv.conf
文件中设置的解析器地址阻止了连接。将其设置为8.8.8.8
即可解决。
答案 1 :(得分:1)
使用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
答案 2 :(得分:0)
您可以在VM上访问Internet吗?尝试:
wget http://gb.archive.ubuntu.com/ubuntu/pool/main/j/jbigkit/libjbig0_2.1-3.1_amd64.deb
如果这不起作用,则说明您存在互联网访问问题。
答案 3 :(得分:0)
错误已清除400 Bad Request
E:无法获取http://gb.archive.ubuntu.com/ubuntu/pool/main/j/jbigkit/libjbig0_2.1-3.1_amd64.deb 400错误请求[IP:91.189.88.161 80]
URL正常。从命令行运行:91.189.88.161 80
# apt update
# apt install nginx
如果这可行,那么这可能是一个Ansible问题。