Check if service exists with Ansible

后端 未结 6 958
面向向阳花
面向向阳花 2020-12-14 14:12

I have an Ansible playbook for deploying a Java app as an init.d daemon.

Being a beginner in both Ansible and Linux I\'m having trouble to conditionally execute task

6条回答
  •  不思量自难忘°
    2020-12-14 14:42

    Another approach for systemd (from Jakuje):

    - name: Check if cups-browsed service exists
      command: systemctl cat cups-browsed
      check_mode: no
      register: cups_browsed_exists
      changed_when: False
      failed_when: cups_browsed_exists.rc not in [0, 1]
    
    - name: Stop cups-browsed service
      systemd:
        name: cups-browsed
        state: stopped 
      when: cups_browsed_exists.rc == 0
    

提交回复
热议问题