1

i'm new to ansible, and i would like to check few hosts for exist/no-exist services to do things based on those facts after.

there is ~100 servers with same debian everywhere, but different workload, so i need to check whether any of services is present and running.

example playbook checks zabbix, mysql and postgres (should check, in fact)

- hosts: all
  remote_user: root
  vars:
      zabb: "{{ ansible_facts.services['zabbix-agent']['state'] == 'running' }}"
      mysql: "{{ ansible_facts.services['mariadb']['state'] == 'running' }}"
      postgres: "{{ ansible_facts.services['postgresql']['state'] == 'running' }}"
  tasks:
    - name: populate
      service_facts:

    - name: checking mysql
      # any action here
      when: mysql
      ignore_errors: yes

    - name: checking postgres
      # any action here
      when: postgres
      ignore_errors: yes

how to avoid failures in resolving services? what is the best way to check if service exist?

there is an option with parsing ps|lsof output via ansible's command module, but this is not look like elegant solution.

ansible version is 2.7.4

Vsevolod
  • 11
  • 1
  • 1
    Possibly relevant: https://stackoverflow.com/questions/30328506/check-if-service-exists-with-ansible – nwinkler Dec 05 '18 at 14:32

0 Answers0