title: How to check if the file has any non-whitespace characters in Ansible
body: <p>I have an ansible task that checks for differences between two files as below:</p>
  
  <pre><code>---
  - name: Collect data
    shell: "diff -c /var/file1.txt /var/file2.txt"
    ignore_errors: yes
    register: outputf
  
  - set_fact:
      statustask: "bad"
    when: outputf.rc != 0
  
  - set_fact:
      statustask: "good"
    when: outputf.rc == 0
  </code></pre>
  
  <p>I want <code>statustask: "good"</code> if either /var/file1.txt or /var/file2.txt is empty. </p>
  
  <p>Note: the size of the file may not be zero still it would be empty considering it has whitespaces.</p>
  
  <p>Thus I'm looking for non-whitespace data in the file.</p>
  
  <p>I can try shell module with <code>grep -q '[^[:space:]]</code> /var/file1.txt'` results to determine if the file has non-whitespace characters but wanted to know if there is a more elegant approach to this?</p>