title: How to print command output in Ansible when there is a condition?
body: <p>My ansible code looks something like the following. Problem is this only works when my inventory has dev,qa, perf and prod servers. For example, if my inventory has only dev servers then it fails. Is there any way to avoid this failure ?</p>
  
  <p>I tried changing both <code>cmd_dev_out</code> and <code>cmd_qa_out</code> to <code>cmd_out</code> but that did not help either.</p>
  
  <pre>
  
  - name: Execute
    hosts: all
    tasks:
      - name: Execute against dev
        shell: some command
        register: cmd_dev_out
        when: ( servers are dev )
  
      -  debug: msg="{{ cmd_dev_out }}"
  
      - name: Execute against qa
        shell: some command
        register: cmd_qa_out
        when: ( servers are qa )
  
      -  debug: msg="{{ cmd_qa_out }}"
  
      ....... More conditions below .....
  </pre>