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

我想使用Ansible在Ubuntu 16.04的远程机器上安装Docker,并按照https://docs.docker.com/engine/installation/linux/ubuntu/上的官方文档。 似乎所有的工作,但当任务到达的任务名称“安装docker”,我得到“没有包匹配”dockerce“可用”。

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

- 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 

哪里有问题?

或者,如果Ansible version> = 2.0,则可以使用通用OS包pipe理器模块:

 - name: install docker package: name: docker-ce state: present 

问题是apt存储库被错误地添加。 下面一行是从字面上加$(lsb_release -cs)而不是插值的:

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

你想要的是使用Ansible的事实,而不是像这样:

 repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable 

这应该在/etc/apt/sources.list.d/download_docker_com_repo.list文件中为您提供以下内容:

 deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable 

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

你没有运行apt-get更新,所以新的回购没有被读取

你需要运行

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" sudo apt-get update sudo apt-get install docker-ce