playbook安装docker

2022-11-21 19:40:20 浏览数 (1)

docker.yaml文件

代码语言:javascript复制
- hosts: test #自己添加的主机清单
  remote_user: root
  tasks:
    - name: 安装yum-utils工具
      shell: yum -y install yum-utils
    - name: 安装docker的repo源
      shell: yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
    - name: 安装docker
      shell: yum -y install docker-ce

检测yaml

代码语言:javascript复制
[root@host1 ~]# ansible-playbook --syntax-check docker.yml 

playbook: docker.yml

执行

代码语言:javascript复制
[root@host1 ~]# ansible-playbook  docker.yml 

PLAY [test] ********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [192.168.1.20]
ok: [192.168.1.10]

TASK [安装yum-utils工具] ***********************************************************
[WARNING]: Consider using the yum module rather than running 'yum'.  If you
need to use command because yum is insufficient you can add 'warn: false' to
this command task or set 'command_warnings=False' in ansible.cfg to get rid of
this message.
changed: [192.168.1.20]
changed: [192.168.1.10]

TASK [安装docker的repo源] **********************************************************
changed: [192.168.1.20]
changed: [192.168.1.10]

TASK [安装docker] ****************************************************************
changed: [192.168.1.20]
changed: [192.168.1.10]

PLAY RECAP *********************************************************************
192.168.1.10               : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
192.168.1.20               : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
[root@host1 ~]# systemctl start docker
[root@host1 ~]# docker --version
Docker version 20.10.2, build 2291f61

0 人点赞