title: Ansible - How to skip registering a variable if the when condition is not met
body: <pre><code>-  shell: "echo 'hi'"
     register: output
  -  shell: "ps -ef"
     register: output
     when: output.stdout =="hello"
   - debug: var=output
  </code></pre>
  
  <p>The final output variable is defined as below:</p>
  
  <pre><code>TASK [Display output] **********************************************************
  
      ok: [localhost] =&gt; 
  {
      "output": 
     {
          "changed": false,
          "skip_reason": "Conditional check failed",
          "skipped": true
      }
  }
  </code></pre>
  
  <p>Even though the task 2 is skipped, the variable gets registered. How can I skip the register if the condition is not met?</p>