我想使用Ubuntu 16.04在远程计算机上安装Docker,使用Ansible并遵循https://docs.docker.com/engine/installation/linux/ubuntu/的官方文档。 一切似乎都有效,但是当ansible以名称"安装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
问题出在哪里?
答案 0 :(得分:2)
问题是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密钥(根据安装说明)。
答案 1 :(得分:1)
你没有运行apt-get update,所以新的repo没有被阅读
答案 2 :(得分:0)
如果Ansible版本> = 2.0:
,您可以使用通用OS包管理器模块- name: install docker
package:
name: docker-ce
state: present
答案 3 :(得分:0)
我知道您正在搜索ubuntu安装,但是对于其他用户(如我之前搜索的),我将共享我的centos版本(正在运行):
---
- name: Install docker
gather_facts: true
check_mode: no # yes only for test
hosts: swarm_cluster
vars:
sudoers:
- ansible
become: true
tasks:
#################### ABSENT ########################
# systemctl status docker
- name: Stop and disable docker service
service:
name: docker
enabled: no
state: stopped
register: docker_service_result
failed_when: "docker_service_result is failed and 'Could not find the requested service' not in docker_service_result.msg"
# grep /etc/group -e "docker"
- name: Remove docker group
group:
name: docker
state: absent
system: yes
- name: Remove 'docker', 'yum-utils', 'lvm2' and 'device-mapper-persistent-data' packages
package:
name: '{{ item }}'
state: absent
with_items:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
- docker-ce
- docker-ce-cli
- containerd.io
- lvm2
- device-mapper-persistent-data
- yum-utils
# sudo vi /etc/yum.repos.d/docker-ce.repo
- name: Remove docker repository
yum_repository:
name: docker-ce
state: absent
#################### PRESENT ########################
- name: Install 'yum-utils', 'lvm2' and 'device-mapper-persistent-data'
package:
name: '{{ item }}'
state: latest
with_items:
- yum-utils
- device-mapper-persistent-data
- lvm2
- name: Install docker repository
yum_repository:
name: '{{ item.name }}'
description: '{{ item.desc }}'
file: docker-ce
baseurl: '{{ item.baseurl }}'
enabled: '1'
gpgcheck: yes
gpgkey: 'https://download.docker.com/linux/centos/gpg'
state: present
with_items:
- { name: 'docker-ce-stable', desc: 'Docker CE Stable - $basearch', baseurl: 'https://download.docker.com/linux/centos/7/$basearch/stable'}
- { name: 'docker-ce-edge', desc: 'Docker CE Edge - $basearch', baseurl: 'https://download.docker.com/linux/centos/7/$basearch/edge'}
- { name: 'docker-ce-test', desc: 'Docker CE Test - $basearch', baseurl: 'https://download.docker.com/linux/centos/7/$basearch/test'}
- name: Install docker
package:
name: '{{ item }}'
state: latest
with_items:
- docker-ce
- docker-ce-cli
- containerd.io
- name: Start docker service
service:
name: docker
state: started
enabled: yes
- name: Test Docker with hello world example
shell: 'docker run hello-world'
register: hello_world_output
- name: Show output of hello word example
debug:
msg: 'Container output: {{ hello_world_output.stdout }}'
- name: Create docker group
group:
name: docker
state: present
system: yes
- name: Add ansible to docker group
user:
name: ansible
groups: docker
append: yes
- name: Reboot server
shell: 'sleep 1 && reboot'
async: 1
poll: 0
答案 4 :(得分:-1)
你需要运行
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