Execution
Date 15 Sep 2024 07:45:33 +0100
Duration 00:00:01.21
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.11
ara 1.7.2 / 1.7.2
Python 3.10.10
Summary
1 Hosts
2 Tasks
2 Results
2 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/test_zulip.yaml

---
- name: Test plesk on host
  hosts: all
  tasks:
    - name: Check if the binary exists on the remote host
      test_z:
        binary_path: "/sbin/plesk"
      register: plesk_check_result

    - name: Aggregate binary check results
      ansible.builtin.set_fact:
        plesk_found_on_hosts: "{{ plesk_found_on_hosts | default([]) + [inventory_hostname] }}"
      when: plesk_check_result.binary_exists | bool

- name: Send message
  hosts: localhost
  connection: local
  gather_facts: false
  vars_files:
    - zulip_vars.yml
  tasks:
    - name: Gather hosts where Plesk was found
      ansible.builtin.set_fact:
        remote_hosts_with_plesk: "{{ groups['all'] | select('match', hostvars[item].plesk_found_on_hosts is defined) | list }}"
      loop: "{{ groups['all'] }}"

    - name: Send notification to Zulip if binary exists on any remote host
      when: remote_hosts_with_plesk | length > 0
      block:
        - name: Notify about the found binary using apprise
          ansible.builtin.command: >
            apprise zulip://{{ bot_name }}@{{ zulip_url }}/{{ zulip_token }}/{{ zulip_topic }}
                    -t "Plesk Binary Status"
                    -b "Binary found on the following hosts: {{ remote_hosts_with_plesk | join(', ') }}"
          changed_when: false