My goal is to find a way to combine the two statements below but am coming up short. For this instance, I have Package1 and Package2 that are being installed regardless of rhel version. However, Package3 will be a different package depending on OS version. Seems redundant and there should be a way to combine, but is this the best way to go about it? Any feedback is definitely welcome.
- name: Install Packages
yum:
name: "{{ item }}"
state: latest
loop:
- package1
- package2
- package3A (Only for RHEL8 versions)
when: "{{ ansible_distribution_version }} >= 8.0"
- name: Install Packages
yum:
name: "{{ item }}"
state: latest
loop:
- package1
- package2
- package3B (Only for RHEL7 versions)
when: "{{ ansible_distribution_version }} < 8.0"