title: Ansible ping result into Jinja2 template
body: <p>I would like to make an Jinja2 template from the following Ansible script. Basically, the script checks if a host is reachable or not.</p>
  
  <pre><code>---
  - name: check reachable hosts
    hosts: group1
    gather_facts: no
    tasks:
    - set_fact:
      ping_state: "failed"
    - debug: msg="play hosts {{ ansible_play_batch }}"
      run_once: true
    - ping:
      register: ping_result
      ignore_errors: yes
    - group_by: key=reachable
      when: ping_result|success
    - set_fact:
      ping_state: "OK"
  
  - name: run command
    hosts: reachable
    become: yes
    gather_facts: yes
    tasks:
    - debug: msg="this is {{ ansible_hostname }}"
  
  - name: print ping facts
    hosts: group1
    gather_facts: no
    tasks:
    - meta: clear_host_errors
    - debug:
      var: ping_state
  </code></pre>
  
  <p>In the Jinja2 template I would like to have all hostnames with their ping state. How I can achieve this?</p>
  
  <p>Best regards,</p>
  
  <p>Romain</p>