Ansible-playbook一键安装docker
hosts: kubernetes#定义的主机组,即应用的主机remote_user: root# 远程用户为rootvars:project_directory: /opt/docker/ansible_playbookstasks:name:docker installshell: sudo yum install -y yum-utils de...
·
一、环境准备
1.需要提前配置好daemon.json文件
{
"registry-mirrors": ["这里写阿里云镜像地址"],
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
2.安装的docker版本为17.03.2
二、编写剧本
[root@master1 ansible_playbooks]# vim docker_install.yaml
---
- hosts: kubernetes #定义的主机组,即应用的主机
remote_user: root # 远程用户为root
vars:
project_directory: /opt/docker/ansible_playbooks
tasks:
- name: docker install
shell: sudo yum install -y yum-utils device-mapper-persistent-data lvm2 rsync telnet apr apr-util zip unzip lrzsz
- shell: sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- shell: sudo yum makecache fast
- shell: sudo yum install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
- shell: sudo yum -y install docker-ce-17.03.2.ce
- name: docker config dir
shell: sudo mkdir -p /etc/docker
- name: file transfer
synchronize: src=/etc/docker/daemon.json dest=/etc/docker/daemon.json rsync_opts=-avuz
notify: #上一个任务的运行状态为changed后触发,否则不触发
- restart docker
handlers:
- name: restart docker
service: name=docker enabled=yes daemon_reload=yes state=restarted
更多推荐
已为社区贡献1条内容
所有评论(0)