From 247d4899db755a5e733415f02ac92cdc3c60fcdf Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Thu, 28 Mar 2024 21:50:32 -0400 Subject: [PATCH] using facts instead of template lookup --- ping.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/ping.yml b/ping.yml index 74f161d..eb2b9c1 100644 --- a/ping.yml +++ b/ping.yml @@ -7,7 +7,7 @@ tasks: - name: Wait for connection ansible.builtin.wait_for_connection: - timeout: 3 + timeout: 5 - name: Test target host connectivity ansible.builtin.command: @@ -20,9 +20,26 @@ - name: Clear host errors ansible.builtin.meta: clear_host_errors - - name: Ping check results + # - name: Ping check results + # ansible.builtin.debug: + # msg: "{{ lookup('template', 'ping_results.j2') | from_yaml }}" + # run_once: true # noqa: run-once[task] + # delegate_to: localhost + + - name: Set facts + ansible.builtin.set_fact: + successful_hosts: "{{ successful_hosts | default([]) + ansible_play_batch }}" + failed_hosts: "{{ failed_hosts | default([]) + ansible_play_hosts_all | difference(ansible_play_batch) }}" + + - name: Successful Hosts ansible.builtin.debug: - msg: "{{ lookup('template', 'ping_results.j2') | from_yaml }}" + msg: "{{ successful_hosts }}" + run_once: true # noqa: run-once[task] + delegate_to: localhost + + - name: Failed Hosts + ansible.builtin.debug: + msg: "{{ failed_hosts }}" run_once: true # noqa: run-once[task] delegate_to: localhost