Ansible-playbook一键安装docker

  • Post author:
  • Post category:其他


一、环境准备

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



版权声明:本文为qq_32642039原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。