2020-05-24 14:51:01 +08:00
|
|
|
- name: 获取是否已经安装docker
|
2021-05-28 10:11:35 +08:00
|
|
|
shell: 'systemctl is-active docker || echo "NoFound"'
|
2020-05-24 14:51:01 +08:00
|
|
|
register: docker_svc
|
2019-06-09 15:20:09 +08:00
|
|
|
|
2023-09-05 20:51:47 +08:00
|
|
|
- name: 获取docker版本信息
|
|
|
|
shell: "{{ base_dir }}/bin/docker-bin/dockerd --version|cut -d' ' -f3"
|
|
|
|
register: docker_ver
|
|
|
|
connection: local
|
|
|
|
run_once: true
|
|
|
|
tags: upgrade_docker, download_docker
|
|
|
|
|
|
|
|
- name: debug info
|
|
|
|
debug: var="docker_ver"
|
|
|
|
connection: local
|
|
|
|
run_once: true
|
|
|
|
tags: upgrade_docker, download_docker
|
|
|
|
|
|
|
|
- name: 转换docker版本信息为浮点数
|
|
|
|
set_fact:
|
|
|
|
DOCKER_VER: "{{ docker_ver.stdout.split('.')[0]|int + docker_ver.stdout.split('.')[1]|int/100 }}"
|
|
|
|
connection: local
|
|
|
|
run_once: true
|
|
|
|
tags: upgrade_docker, download_docker
|
|
|
|
|
2023-09-05 19:24:03 +08:00
|
|
|
- name: 已安装提示
|
|
|
|
debug:
|
|
|
|
msg: "docker 服务已安装"
|
|
|
|
when: "'NoFound' not in docker_svc.stdout"
|
2019-07-17 22:53:24 +08:00
|
|
|
|
2019-02-28 16:06:26 +08:00
|
|
|
- block:
|
|
|
|
- name: 准备docker相关目录
|
|
|
|
file: name={{ item }} state=directory
|
|
|
|
with_items:
|
|
|
|
- "{{ bin_dir }}"
|
2021-04-15 23:19:40 +08:00
|
|
|
- "/etc/docker"
|
2019-02-28 16:06:26 +08:00
|
|
|
|
|
|
|
- name: 下载 docker 二进制文件
|
2023-09-05 19:24:03 +08:00
|
|
|
copy: src={{ item }} dest={{ bin_dir }}/ mode=0755
|
|
|
|
with_fileglob:
|
|
|
|
- "{{ base_dir }}/bin/docker-bin/*"
|
2019-02-28 16:06:26 +08:00
|
|
|
tags: upgrade_docker, download_docker
|
|
|
|
|
2023-09-05 19:24:03 +08:00
|
|
|
- name: 配置docker daemon
|
2019-02-28 16:06:26 +08:00
|
|
|
template: src=daemon.json.j2 dest=/etc/docker/daemon.json
|
|
|
|
|
|
|
|
- name: 创建docker的systemd unit文件
|
|
|
|
template: src=docker.service.j2 dest=/etc/systemd/system/docker.service
|
|
|
|
tags: upgrade_docker, download_docker
|
|
|
|
|
|
|
|
- name: 开机启用docker 服务
|
|
|
|
shell: systemctl enable docker
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: 开启docker 服务
|
|
|
|
shell: systemctl daemon-reload && systemctl restart docker
|
|
|
|
tags: upgrade_docker
|
2020-03-31 18:05:34 +08:00
|
|
|
|
2019-02-28 16:06:26 +08:00
|
|
|
- name: 轮询等待docker服务运行
|
2021-05-28 10:11:35 +08:00
|
|
|
shell: "systemctl is-active docker.service"
|
2019-02-28 16:06:26 +08:00
|
|
|
register: docker_status
|
2021-05-28 10:11:35 +08:00
|
|
|
until: '"active" in docker_status.stdout'
|
2019-02-28 16:06:26 +08:00
|
|
|
retries: 8
|
|
|
|
delay: 2
|
|
|
|
tags: upgrade_docker
|
|
|
|
|
|
|
|
# 配置 docker 命令软链接,方便单独安装 docker
|
|
|
|
- name: 配置 docker 命令软链接
|
|
|
|
file: src={{ bin_dir }}/docker dest=/usr/bin/docker state=link
|
2019-03-28 18:44:10 +08:00
|
|
|
ignore_errors: true
|
2021-09-25 11:41:34 +08:00
|
|
|
when: "'NoFound' in docker_svc.stdout"
|