title: Ansible register fails when there is no output from shell command
body: <p>I am trying to check if a service is running then register its output to some variable if its not running then start the service. Below is my Ansible playbook snippet.</p>
  
  <pre><code>- hosts: localhost
    tasks:
    - name: check if service is running
      shell: pgrep node
      register: pgrep
    - name: stop running service
      shell: pkill node
      when: pgrep.stdout_lines != ''
      tags:
      - stop
    - name: start running service
      shell: pkill node
      when: pgrep.stdout_lines == ''
      tags:
      - start
  </code></pre>
  
  <p>Now in the above case if the process is not running then the <code>pgrep node</code> command returns exit status code as 1 which fails the "check if service is running" tasks and aborts further execution of tasks. I know by setting <code>ignore_errors: true</code> will ignore the error and proceed ahead, but it fails the Ansible runs. Is there a way where we can handle this gracefully?</p>