docker-install-v0.1-alpha

😄 Written by Zak Zhu

docker-install-v0.1-alpha/
├── inventory
├── roles
│ └── docker
│ ├── defaults
│ │ └── main.yml
│ ├── files
│ ├── handlers
│ │ └── main.yml
│ ├── meta
│ │ └── main.yml
│ ├── README.md
│ ├── tasks
│ │ └── main.yml
│ ├── templates
│ │ └── daemon.json.j2
│ ├── tests
│ │ ├── inventory
│ │ └── test.yml
│ └── vars
│ └── main.yml
└── setup.yml


setup.yml

- name: Install Docker
  hosts: all
  gather_facts: no
  vars:
    registry_accelerator: 
      url: "阿里云镜像加速器地址"

    yum_repository:
      base_repo:
        name: "CentOS-Base.repo"
        url: "http://mirrors.aliyun.com/repo/Centos-7.repo"
      epel_repo:
        name: "epel.repo"
        url: "http://mirrors.aliyun.com/repo/epel-7.repo"
      docker_repo:
        name: "docker-ce.repo"
        url: "https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo"
  roles:
    - docker

roles/docker/tasks/main.yml

---
# tasks file for docker
- name: Add yum repository
  get_url:
    url: "{{ item.value.url }}"
    dest: "/etc/yum.repos.d/{{ item.value.name }}"
  loop: "{{ yum_repository | dict2items }}"

- name: Install docker-ce
  yum:
    name: docker-ce
    state: present

- name: Create /etc/docker directory
  file:
     path: /etc/docker
     state: directory
     mode: '0755'

- name: Create docker configuration file
  template:
    src: daemon.json.j2
    dest: /etc/docker/daemon.json
  notify:
    - restart docker

- name: Start and enable docker
  systemd:
    name: docker
    state: started
    enabled: yes

roles/docker/templates/daemon.json.j2

{
    "registry-mirrors": ["{{ registry_accelerator.url }}"]
}

roles/docker/handlers/main.yml

---
# handlers file for docker
- name: restart docker
  systemd:
    name: docker
    state: restarted 
posted @ 2019-12-28 10:15  ZakZhu  阅读(268)  评论(0编辑  收藏  举报