Ansible:没有适用于 docker-ce 的软件包

Seg*_*ult 2 ansible docker

我想在装有 Ubuntu 16.04 的远程计算机上安装 Docker,使用 Ansible 并遵循https://docs.docker.com/engine/installation/linux/ubuntu/上的官方文档。一切似乎都有效,直到 ansible 到达名称为“install Docker”的任务,我得到“没有可用的与‘docker-ce’匹配的包”。

剧本的以下部分,从设置存储库的点开始:

- name: set the stable repository
    apt_repository: 
      repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable
      

  - name: Update all packages to the latest version
    apt:
      upgrade: dist

  - name: install Docker
    apt:
      name: docker-ce
      state: present
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?

And*_*inn 5

问题是 apt 存储库添加不正确。下面这行字面上是添加了$(lsb_release -cs)并且没有进行插值:

repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable
Run Code Online (Sandbox Code Playgroud)

你想要的是使用 Ansible 事实来代替,如下所示:

repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable
Run Code Online (Sandbox Code Playgroud)

这应该会在/etc/apt/sources.list.d/download_docker_com_repo.list文件中显示以下内容:

deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable
Run Code Online (Sandbox Code Playgroud)

注意:您可能apt_key还需要导入 GPG 密钥(按照安装说明)。