ansible playbook 安裝docker


1.新增host配置到/etc/ansible/hosts文件中

[docker]
192.168.43.95

2.配置無密碼登錄

# 配置ssh,默認rsa加密,保存目錄(公鑰)~/.ssh/id_rsa.pub
ssh-keygen -t rsa

# 配置無密碼登陸,這里需要分別4次發送至4台服務器
ssh-copy-id -i ~/.ssh/id_rsa.pub root@ip

3.編寫playbook

---
- hosts: docker
  remote_user: root
  tasks:
    - name: install yum-utils
      yum: name=yum-utils state=present
    - name: add docker repo
      shell: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    - name: install docer-ce
      yum:
        name: docker-ce
        state: present
    - name: install docker-ce-cli
      yum:
        name: docker-ce-cli
        state: present
    - name: install containerd.io
      yum:
        name: containerd.io
        state: present
    - name: config mirro
      copy: src=~/docker-daemon.json dest=/etc/docker/daemon.json
      tags: configmirro
    - name: start enable docker
      service: name=docker state=started enabled=true
    - name: restrat
      shell: sudo systemctl daemon-reload && sudo systemctl restart docker
      tags: restart

mirror配置

[root@localhost ~]# cat docker-daemon.json
{
  "registry-mirrors": [
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn"
  ]
}

 

4.運行playbook

 ansible-playbook -v install_docker-ce.yml

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM