打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ansible安装docker脚本

使用ansible批量在服务器安装docker

注意:

1. ansible版本是2.8,其他版本也都是支持的,低版本请自行百度下,看下模块的使用方法

2. 我修改了docker的存储路径,默认是在/var/lib/docker,系统盘太小,所以单独挂载了一块数据盘,挂载到了/data,执行脚本请确定有/data此目录

3. 使用直接修改 yourhosts即可

4. 配置范例

cat /etc/ansible/hosts

[yourhosts]

web01 ansible_host=192.168.10.30 ansible_port=22 ansible_user=root ansible_password=1qaz

web02 ansible_host=192.168.10.23 ansible_port=22 ansible_user=root ansible_password=2wsx

5. 执行脚本

ansible-playbook docker_install.yml

6. 脚本内容:

cat /usr/local/srcipt/docker_install.yml

---

  - hosts: yourhosts

    remote_user: root

    tasks:

      - name: Add epel-release repository

        yum_repository:

          name: epel

          description: EPEL YUM repo

          baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/

          gpgcheck: no

      - name: Installing System Dependency Packages

        yum:

          name:

            - yum-utils

            - device-mapper-persistent-data

            - lvm2

          state: present

          disable_gpg_check: yes

      - name: Add Docker Yum Repo

        shell: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

      - name: Install docker

        yum:

          name: docker-ce

          state: present

          disable_gpg_check: yes

        notify: install docker

    handlers:

      - name: Created symlink from docker.services

        listen: install docker

        shell: systemctl enable docker

      - name: Create docker configuration file paths

        listen: install docker

        file:

          path: /etc/docker

          state: directory

      - name: Create docker data paths

        listen: install docker

        file:

          path: /data/docker

          state: directory

      # 注意 marker中不能有值,因为docker配置文件的#不是注释,有可能启动失败

      - name: Create configuration

        listen: install docker

        blockinfile:

          path: /etc/docker/daemon.json

          create: yes

          content: |

              {

              "live-restore": true,

              "registry-mirrors": ["https://pee6w651.mirror.aliyuncs.com"]

              }

          marker: " "

          # marker: "#{mark} ansible aliyun config"

      - name: Modify the data file path

        listen: install docker

        lineinfile:

          path: /usr/lib/systemd/system/docker.service

          regexp: "^ExecStart"

          line: ExecStart=/usr/bin/dockerd --graph /data/docker

      - name: daemon reload

        listen: install docker

        shell: systemctl disable docker && systemctl enable docker && systemctl daemon-reload

      - name: start docker server

        listen: install docker

        service:

          name: docker

          state: started

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
linux下SSH服务利用shell脚本实现密钥的批量分发与执行
ansible playbook 安装docker
centos7安装docker
如何创建CentOS系统的Docker基础镜像?
一 安装docker(详解)
163yum源
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服