title: Checking output of a shell command in ansible
body: <p>I'm trying to write an Ansible script that runs a shell pipeline, and determines whether to terminate the playbook's execution based on that pipeline's output.</p>
  
  <p>Here is the problematic code:</p>
  
  <pre><code>  - name: Check if the number of HITACHI devices is equal to 1
      shell: lsscsi | grep HITACHI | awk '{print $6}' | wc -l
      register: numOfDevices
      when: numOfDevices|int  == 1
  </code></pre>
  
  <p>Here is the error:</p>
  
  <pre><code>{  
     "failed":true,
     "msg":"The conditional check 'numOfDevices|int  == 1' failed.  
  The error was: error while evaluating conditional (numOfDevices|int  == 1): 'numOfDevices' is undefined\n\nThe error appears to have been in '/etc/ansible/config/test.yml': line 14, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - name: Check if the number of HITACHI devices is equal to 1\n    ^ here\n"
  }
  </code></pre>
  
  <p>Can someone tells me what could be the issue?</p>