ansible安装docker
时间: 2023-11-20 20:59:08 浏览: 168
以下是使用Ansible安装Docker的步骤:
1.确保已经安装了Ansible软件,并且已经设置好了主机名为ansible。
2.创建一个名为docker_install.yml的Ansible Playbook文件,并在其中添加以下内容:
```yaml
---
- name: Install Docker
hosts: docker2
become: true
tasks:
- name: Install required packages
yum:
name:
- yum-utils
- device-mapper-persistent-data
- lvm2
state: present
- name: Add Docker repository
yum_repository:
name: docker-ce
baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/
description: Docker CE Stable - $basearch
gpgcheck: yes
gpgkey: https://download.docker.com/linux/centos/gpg
enabled: yes
- name: Install Docker CE
yum:
name: docker-ce
state: present
- name: Start Docker service
service:
name: docker
state: started
```
3.在终端中运行以下命令来执行Ansible Playbook文件:
```shell
ansible-playbook docker_install.yml
```
4.等待执行完成后,Docker就已经成功安装在被控制的主机上了。
阅读全文