when: ansible conditional's based on distribution major version

I am trying to copy over .rpm files based on the major version of the operating system I believe I am referencing the ansible_facts part incorrectly does anyone have an example of the right way?

tasks:

  • name: Copy kernel RHEL6
    copy:
    src: /etc/ansible/files/individual_files/test/kernel-2.6.32-754.15.3.el6.x86_64.rpm
    dest: /tmp/kernel-2.6.32-754.15.3.el6.x86_64.rpm
    owner: root
    group: root
    mode: 0644
    when: ansible_facts[‘distribution_major_version’] == ‘6’

  • name: Copy kernel RHEL6 firmware
    copy:
    src: /etc/ansible/files/individual_files/test/kernel-firmware-2.6.32-754.15.3.el6.noarch.rpm
    dest: /tmp/kernel-firmware-2.6.32-754.15.3.el6.noarch.rpm
    owner: root
    group: root
    mode: 0644
    when: ansible_facts[‘ansible_distribution_major_version’] == ‘6’

  • name: Copy kernel RHEL7
    copy:
    src: /etc/ansible/files/individual_files/rhel7/kernel-3.10.0-1062.el7.x86_64.rpm
    dest: /tmp/kernel-3.10.0-1062.el7.x86_64.rpm
    owner: root
    group: root
    mode: 0644
    when: ansible_facts[‘ansible_distribution_major_version’] == ‘7’

  • name: Copy kernel RHEL7 firmware
    copy:
    src: /etc/ansible/files/individual_files/rhel7/linux-firmware-20190429-72.gitddde598.el7.noarch.rpm
    dest: /tmp/linux-firmware-20190429-72.gitddde598.el7.noarch.rpm
    owner: root
    group: root
    mode: 0644
    when: ansible_facts[‘ansible_distribution_major_version’] == ‘7’

Jeffrey,

Try:

when: ansible_distribution_major_version == '7'

That worked thank you very much!