2018-06-14 23:34:03 +08:00
|
|
|
|
- name: 准备docker相关目录
|
|
|
|
|
file: name={{ item }} state=directory
|
|
|
|
|
with_items:
|
|
|
|
|
- "{{ bin_dir }}"
|
|
|
|
|
- /etc/docker
|
|
|
|
|
|
2019-02-21 15:13:18 +08:00
|
|
|
|
# 18.09.x 版本二进制名字有变化,需要做判断
|
|
|
|
|
- name: 获取docker版本信息
|
|
|
|
|
shell: "{{ base_dir }}/bin/dockerd --version"
|
|
|
|
|
register: docker_ver
|
|
|
|
|
connection: local
|
|
|
|
|
run_once: true
|
|
|
|
|
|
2017-11-11 19:14:21 +08:00
|
|
|
|
- name: 下载 docker 二进制文件
|
|
|
|
|
copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755
|
|
|
|
|
with_items:
|
|
|
|
|
- docker-containerd
|
|
|
|
|
- docker-containerd-shim
|
|
|
|
|
- docker-init
|
|
|
|
|
- docker-runc
|
|
|
|
|
- docker
|
|
|
|
|
- docker-containerd-ctr
|
|
|
|
|
- dockerd
|
|
|
|
|
- docker-proxy
|
2018-09-11 23:12:25 +08:00
|
|
|
|
tags: upgrade_docker, download_docker
|
2019-02-21 15:13:18 +08:00
|
|
|
|
when: "'version 18.09' not in docker_ver.stdout"
|
|
|
|
|
|
|
|
|
|
- name: 下载 docker 二进制文件(>= 18.09.x)
|
|
|
|
|
copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755
|
|
|
|
|
with_items:
|
|
|
|
|
- containerd
|
|
|
|
|
- containerd-shim
|
|
|
|
|
- docker-init
|
|
|
|
|
- runc
|
|
|
|
|
- docker
|
|
|
|
|
- ctr
|
|
|
|
|
- dockerd
|
|
|
|
|
- docker-proxy
|
|
|
|
|
tags: upgrade_docker, download_docker
|
|
|
|
|
when: "'version 18.09' in docker_ver.stdout"
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
|
|
|
|
- name: docker命令自动补全
|
|
|
|
|
copy: src=docker dest=/etc/bash_completion.d/docker mode=0644
|
|
|
|
|
|
|
|
|
|
- name: docker国内镜像加速
|
2018-08-12 16:47:39 +08:00
|
|
|
|
template: src=daemon.json.j2 dest=/etc/docker/daemon.json
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
|
|
|
|
- name: flush-iptables
|
2019-02-09 11:50:18 +08:00
|
|
|
|
shell: "iptables -P INPUT ACCEPT \
|
|
|
|
|
&& iptables -F && iptables -X \
|
2017-11-28 23:27:38 +08:00
|
|
|
|
&& iptables -F -t nat && iptables -X -t nat \
|
|
|
|
|
&& iptables -F -t raw && iptables -X -t raw \
|
|
|
|
|
&& iptables -F -t mangle && iptables -X -t mangle"
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2017-12-05 09:59:56 +08:00
|
|
|
|
- name: 创建docker的systemd unit文件
|
|
|
|
|
template: src=docker.service.j2 dest=/etc/systemd/system/docker.service
|
2018-09-11 23:12:25 +08:00
|
|
|
|
tags: upgrade_docker, download_docker
|
2017-12-05 09:59:56 +08:00
|
|
|
|
|
2018-04-10 18:33:24 +08:00
|
|
|
|
- name: 开机启用docker 服务
|
|
|
|
|
shell: systemctl enable docker
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
2017-12-05 09:59:56 +08:00
|
|
|
|
- name: 开启docker 服务
|
2018-04-10 18:33:24 +08:00
|
|
|
|
shell: systemctl daemon-reload && systemctl restart docker
|
2018-09-11 23:12:25 +08:00
|
|
|
|
tags: upgrade_docker
|
2017-12-02 11:39:12 +08:00
|
|
|
|
|
|
|
|
|
## 可选 ------安装docker查询镜像 tag的小工具----
|
2018-03-29 09:24:04 +08:00
|
|
|
|
# 先要安装轻量JSON处理程序‘jq’,已在 prepare 节点安装
|
2017-12-02 11:39:12 +08:00
|
|
|
|
- name: 下载 docker-tag
|
|
|
|
|
copy: src=docker-tag dest={{ bin_dir }}/docker-tag mode=0755
|
2019-02-21 15:13:18 +08:00
|
|
|
|
|
|
|
|
|
- name: 轮询等待docker服务运行
|
|
|
|
|
shell: "systemctl status docker.service|grep Active"
|
|
|
|
|
register: docker_status
|
|
|
|
|
until: '"running" in docker_status.stdout'
|
|
|
|
|
retries: 8
|
|
|
|
|
delay: 2
|
|
|
|
|
tags: upgrade_docker
|