ansible docker 修改配置自动重启

ansible docker 修改配置自动重启

---

- name: ansible playbook
  hosts: all
  remote_user: root
  become: yes
  tasks:
    - name: 安装 docker
      yum:
        name: docker-engine
        state:latest
      - name: 启动 docker
        service:
          name: docker
          state: started #主机每次重启后服务的状态,可选值 [started, stoped, reloaded, restarted]
      - name: 配置 docker 服务
        copy:
          src: ./file/docker.service
          dest: /etc/systemd/system/
        notify:
          - 重启 sysytemd
          - 重启 docker              
        
  handlers:
     - name 重启 systemd
       command: /usr/bin/systemctl daemon-reload
     - name 重启 docker           
       service: 
         name: docker
         state: restart

查看服务状态:

ansible all -a "systemctl show docker"