首先配置好docker安装的yum源
wget -P /etc/yum.repos.d/ https://download.docker.com/linux/centos/docker-ce.repo
docker.yml
- hosts: node
remote_user: root
tasks:
- name: setup yum-utils
yum: name=yum-utils state=present
- name: setup device-mapper-persistent-data
yum: name=device-mapper-persistent-data state=present
- name: setup lvm2
yum: name=lvm2 state=present
- name: cp docker.repo
copy:
src: "/etc/yum.repos.d/docker-ce.repo"
dest: "/etc/yum.repos.d/docker-ce.repo"
- name: setup docker-ce
yum: name=docker-ce state=present
- name: start docker
service: name=docker.service enabled=yes state=started
安装过程
[root@haiou roles]# ansible-playbook docker.yml
PLAY [node] ********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.0.132]
ok: [192.168.0.131]
TASK [setup yum-utils] *********************************************************
ok: [192.168.0.132]
ok: [192.168.0.131]
TASK [setup device-mapper-persistent-data] *************************************
ok: [192.168.0.132]
ok: [192.168.0.131]
TASK [setup lvm2] **************************************************************
ok: [192.168.0.132]
ok: [192.168.0.131]
TASK [cp docker.repo] **********************************************************
ok: [192.168.0.132]
ok: [192.168.0.131]
TASK [setup docker-ce] *********************************************************
ok: [192.168.0.132]
ok: [192.168.0.131]
TASK [start docker] ************************************************************
changed: [192.168.0.132]
changed: [192.168.0.131]
PLAY RECAP *********************************************************************
192.168.0.131 : ok=7 changed=1 unreachable=0 failed=0
192.168.0.132 : ok=7 changed=1 unreachable=0 failed=0
如上,安装成功。
使用ansible node -m command -a "docker -v"检查
[root@feiyu etc]# ansible node -m command -a "docker -v"
192.168.0.132 | SUCCESS | rc=0 >>
Docker version 18.06.0-ce, build 0ffa825
192.168.0.131 | SUCCESS | rc=0 >>
Docker version 18.06.0-ce, build 0ffa825
就此,ansible安装docker成功