title: Ansible set_facts based on OS version not working
body: <p>I want to set the patch based on the OS version. came up with this playbook in Ansible version 2.8. but its giving <code>The task includes an option with an undefined variable.</code> error message in the debug line. </p>
  
  <pre><code>---
  - hosts: all
    gather_facts: yes
    vars:
        patch_name_8: 'centos8-updates'
        patch_name_7: 'centos7-updates'
    tasks:
      - name: Set fact for CentOS 7
        set_fact:
          install_patch_name: "{{ patch_name_7 }}"
        when: ansible_distribution_major_version == 7
  
      - name: Set fact for CentOS 8
        set_fact:
          install_patch_name: "{{ patch_name_8 }}"
        when: ansible_distribution_major_version == 8
  
      - name: patch name display
        debug:
          msg: "install {{ install_patch_name }}"
  </code></pre>
  
  <p>How to set the <code>install_patch_name</code> variable value based on the OS version?</p>
  
  <p><strong>adding the error message:</strong></p>
  
  <pre><code>TASK [patch name display] ************************************************************************************************************
  fatal: [host01]: FAILED! =&gt; {"msg": "The task includes an option with an undefined variable. The error was: 'install_patch_name' is undefined\n\nThe error appears to be in 't.yaml': line 23, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n
  - name: patch name display\n      ^ here\n"}
  </code></pre>
  
  <p>thanks</p>