Ansible安装docker-ce(三)
一、入口docker.yml文件
[root@ansible ~]# cat ansible/docker.yml - hosts: "{{ group }}" remote_user: root roles: - role: docker
二、roles目录及文件
2.1 roles目录结构
[root@ansible ~]# tree ansible/roles/docker/ ansible/roles/docker/ ├── files │ ├── daemon.json │ └── docker-ce.repo └── tasks ├── cp_daemon.yml ├── cp_repo.yml ├── install_docker.yml ├── login.yml ├── main.yml ├── start.yml └── yum_rely.yml
2.2 tasks目录及文件内容
[root@ansible ~]# cat ansible/roles/docker/tasks/main.yml - include: yum_rely.yml - include: cp_repo.yml - include: install_docker.yml - include: cp_daemon.yml - include: start.yml - include: login.yml
[root@ansible ~]# cat ansible/roles/docker/tasks/yum_rely.yml - name: install rely software packages yum: name=yum-utils,device-mapper-persistent-data,lvm2
[root@ansible ~]# cat ansible/roles/docker/tasks/cp_repo.yml - name: copy repo file copy: src=docker-ce.repo dest=/etc/yum.repos.d/docker-ce.repo
[root@ansible ~]# cat ansible/roles/docker/tasks/install_docker.yml - name: install docker-ce yum: name=docker-ce state=latest
[root@ansible ~]# cat ansible/roles/docker/tasks/cp_daemon.yml - name: copy daemon.json file copy: src=daemon.json dest=/etc/docker/daemon.json
[root@ansible ~]# cat ansible/roles/docker/tasks/start.yml - name: start docker-ce service: name=docker state=restarted enabled=yes
[root@ansible ~]# cat ansible/roles/docker/tasks/login.yml - name: login 192.168.0.69 docker_login: registry: 192.168.0.69 username: admin password: Harbor12345 reauthorize: yes
2.3 files目录及文件内容
[root@ansible ~]# cat ansible/roles/docker/files/daemon.json {"registry-mirrors": ["https://registry.docker-cn.com"], "insecure-registries":["192.168.5.69"] }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@ansible ~]# cat ansible/roles/docker/files/docker-ce.repo [docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/stable enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/stable enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-edge] name=Docker CE Edge - $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/edge enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-edge-debuginfo] name=Docker CE Edge - Debuginfo $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/edge enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-edge-source] name=Docker CE Edge - Sources baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/edge enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test] name=Docker CE Test - $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/test enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/test enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/test enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo $basearch baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/nightly enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
三、执行安装docker
[root@ansible ~]# ansible-playbook ansible/docker.yml -e group=192.168.0.150