「Ansible」- systemd / service

  CREATED BY JENKINSBOT

systemd – Manage services
service – Manage services

service_facts – Return service state information as fact data

检测 systemd 服务

Ansible tips’n’tricks: checking if a systemd service is running

使用 service_facts 可以获取服务信息,该模块支持 systemd, sysv, upstart 三种。

- name: "获取服务信息"
  service_facts:

- name: "如果 Docker 已安装,则重启 Docker 服务"
  when: ansible_facts.services["docker.service"] is defined
  systemd:
  	name: docker.service
  	state: restarted