title: Ansible if-else condition based on gathered fact
body: <p>I would like to see/learn a practical example of if-else logic in ansible based on the fact I gathered from the IOS host. For example if the running firmware version is higher do that, if not - do something else.</p>
  
  <pre><code>- name: task1                                                                                                     
    hosts: all                                                                                                      
    gather_facts: no                                                                                                
    tasks:                                                                                                          
      - name: Get facts                                                                                             
        ios_facts:                                                                                                  
          gather_subset: all                                                                                        
      - name: Define variable (version of compliant image version)                                                  
        set_fact:                                                                                                   
          compliant_image: "16.04"                                                                                  
      - debug:                                                                                                      
          var: ansible_net_image                                                                                    
      - name: Print warning if not compliant                                                                        
        shell: echo "WARNING - Non compliant image! Should be {{ compliant_image }}"                                
        register: compliance_output                                                                                 
        when: ansible_net_image is not search(compliant_image)                                                      
      - name: Print information if ok                                                                               
        shell: echo "INFO - Compliant image"                                                                                          
        register: compliance_output                                                                                 
        when: ansible_net_image is search(compliant_image)                                                          
      - debug: var=compliance_output 
  </code></pre>
  
  <p>This is what I get:</p>
  
  <pre><code>TASK [Define variable (version of compliant image version)] ******
  ok: [My_IOS_Host]
  
  TASK [debug] *****************************************************
  ok: [My_IOS_Host] =&gt; {
      "ansible_net_image": "bootflash:/isr4300-universalk9.03.16.04b.S.155-3.S4b-ext.SPA.bi"
  }
  
  TASK [Print warning if not compliant] ****************************
  changed: [My_IOS_Host]
  
  TASK [Print information if ok] ***********************************
  skipping: [My_IOS_Host]
  
  TASK [debug] *****************************************************
  ok: [My_IOS_Host] =&gt; {
      "compliance_output": {
          "changed": false, 
          "skip_reason": "Conditional result was False", 
          "skipped": true
      }
  }
  </code></pre>
  
  <p>To my understanding the Task: <code>Print information if ok</code> should have a value: <code>INFO - Compliant image</code>.
  I would like to use that information or further logic but it seems that I don't get Ansible's variables logic (yet)</p>