我写了一个有趣的剧本,用于在Ubuntu 16.04 LTS上安装docker。 运行Ansible剧本时,出现apt-get更新错误
我尝试运行所附的剧本代码。
- hosts: docker
become: yes
become_user: root
tasks:
- name: apt-get update
shell: apt-get update -y
- name: Install packages to allow apt to use a repository overHTTPS
shell: sudo apt-get install -y \
apt-transport-https -y \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
- name: Add Docker’s official GPG key
shell: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- name: Use the following command to set up the stable repository
shell: add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu\
$(lsb_release -cs) \
stable"
- name: apt update
shell: apt-get update -y
- name: Installing the docker 17.03.0
shell: apt-get install docker-ce=18.06.1~ce-3-0~ubuntu -y
在安装docker之前,我尝试更新ubuntu服务器,但出现错误
TASK [apt update] **************************************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "apt- get update -y", "delta": "0:00:12.338257",
"end": "2019-04-02 11:58:13.377956", "failed": true, "rc": 100, "start": "2019-04-02 11:58:01.039699",
"stderr": "W: The repository 'https://download.docker.com/linux/ubuntu\\ xenial Release' does not have
a Release file.\nE: Failed to fetch https://download.docker.com/linux/ubuntu\\/dists/xenial/\\/binary-
amd64/Packages 404 Not Found\nE: Some index files failed to download. They have been ignored, or old
ones used instead.", "stdout": "Hit:1 http://us- east1.gce.archive.ubuntu.com/ubuntu xenial InRelease\nH
it:2 http://us-east1.gce.archive.ubuntu.com/ubuntu xenial- updates InRelease\nHit:3 http://us-east1.gce.
archive.ubuntu.com/ubuntu xenial-backports InRelease\nHit:4 http://archive.canonical.com/ubuntu xenial
InRelease\nHit:5 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial InRelease\nHit:6 http://securit
y.ubuntu.com/ubuntu xenial-security InRelease\nIgn:7 https://download.docker.com/linux/ubuntu\\ xenial
InRelease\nIgn:8 https://download.docker.com/linux/ubuntu\\ xenial Release\nIgn:9 https://download.dock
er.com/linux/ubuntu\\ xenial/\\ amd64 Packages\nIgn:10 https://download.docker.com/linux/ubuntu\\ xenia
l/\\ all Packages\nIgn:11 https://download.docker.com/linux/ubuntu\\ xenial/\\ Translation- en_US\nIgn:1
2 https://download.docker.com/linux/ubuntu\\ xenial/\\ Translation-en\nIgn:13 https://download.docker.c
om/linux/ubuntu\\ xenial/stable amd64 Packages\nIgn:14 https://download.docker.com/linux/ubuntu\\ xenia
l/stable all Packages\nIgn:15 https://download.docker.com/linux/ubuntu\\ xenial/stable Translation- en_U
S\nIgn:16 https://download.docker.com/linux/ubuntu\\ xenial/stable Translation-en\nIgn:9 https://downlo
ad.docker.com/linux/ubuntu\\ xenial/\\ amd64 Packages\nIgn:10 https://download.docker.com/linux/ubuntu\
\ xenial/\\ all Packages\nIgn:11 https://download.docker.com/linux/ubuntu\\ xenial/\\ Translation-en_US
\nIgn:12 https://download.docker.com/linux/ubuntu\\ xenial/\\ Translation-en\nIgn:13 https://download.d
ocker.com/linux/ubuntu\\ xenial/stable amd64 Packages\nIgn:14 https://download.docker.com/linux/ubuntu\
\ xenial/stable all Packages\nIgn:15 https://download.docker.com/linux/ubuntu\\ xenial/stable Translati
on-en_US\nIgn:16 https://download.docker.com/linux/ubuntu\\ xenial/stable Translation-en\nIgn:9 https:/
/download.docker.com/linux/ubuntu\\ xenial/\\ amd64 Packages\nIgn:10 https://download.docker.com/linux/
ubuntu\\ xenial/\\ all Packages\nIgn:11 https://download.docker.com/linux/ubuntu\\ xenial/\\ Translatio
n-en_US\nIgn:12 https://download.docker.com/linux/ubuntu\\ xenial/\\ Translation-en\nIgn:13 https://dow
nload.docker.com/linux/ubuntu\\ xenial/stable amd64 Packages\nIgn:14 https://download.docker.com/linux/
ubuntu\\ xenial/stable all Packages\nIgn:15 https://download.docker.com/linux/ubuntu\\ xenial/stable Tr
anslation-en_US\nIgn:16 https://download.docker.com/linux/ubuntu\\ xenial/stable Translation-en\nIgn:9
https://download.docker.com/linux/ubuntu\\ xenial/\\ amd64 Packages\nIgn:10 https://download.docker.com
/linux/ubuntu\\ xenial/\\ all Packages\nIgn:11 https://download.docker.com/linux/ubuntu\\ xenial/\\ Tra
nslation-en_US\nIgn:12 https://download.docker.com/linux/ubuntu\\ xenial/\\ Translation-en\nIgn:13 http
s://download.docker.com/linux/ubuntu\\ xenial/stable amd64 Packages\nIgn:14 https://download.docker.com
/linux/ubuntu\\ xenial/stable all Packages\nIgn:15
答案 0 :(得分:1)
您的shell命令中有很多错误:
-y
命令中apt-get install
\
和"
的组合但更重要的是,当存在执行此工作的模块时,应避免使用shell
模块,在这种情况下,可以使用3个模块:
类似的东西应该起作用:
- hosts: docker
become: yes
tasks:
- name: Update repositories cache and install packages
apt:
name: apt-transport-https ca-certificates curl gnupg-agent software-properties-common
update_cache: yes
- name: Add Docker PGP key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add docker apt repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu ... stable"
state: present
- name: Update repositories cache and install packages
apt:
name: docker-ce
update_cache: yes