Your statements look ok. If I create a test case from the sparse info you provided and what I can observe when gathering facts from my own hosts, I can detect old/recent distributions correctly using your conditions. See my example below.
I suggest you double check the data gathered from your host to understand why it doesn't match. The easiest way for that: from the same host your use to launch your playbook, run
ansible -i path/to/your_inventory.ini your_target_group_name -m setup -a "filter=ansible_distribution*"
Here is the test.yml
playbook I wrote to test your (known-so-far) values and your conditions
---
- name: Statements for checking old/recent distribs
hosts: localhost
gather_facts: false
vars:
os_list:
- ansible_distribution: "Amazon"
ansible_distribution_version: "(Karoo)"
ansible_distribution_major_version: "(Karoo)"
- ansible_distribution: "Amazon"
ansible_distribution_version: "2018.03"
ansible_distribution_major_version: "2018"
- ansible_distribution: "RedHat"
ansible_distribution_version: "6.x"
ansible_distribution_major_version: "6"
- ansible_distribution: "RedHat"
ansible_distribution_version: "7.x"
ansible_distribution_major_version: "7"
tasks:
- name: Check conditions for recent distribs
debug:
msg: "This is a recent distrib"
loop: "{{ os_list }}"
loop_control:
label: "{{ item.ansible_distribution }}-{{ item.ansible_distribution_version }}"
when: (
item.ansible_distribution == "Amazon"
and
item.ansible_distribution_version == "(Karoo)"
)
or
(
item.ansible_distribution == "RedHat"
and
item.ansible_distribution_major_version == "7"
)
- name: Check conditions for old distribs
debug:
msg: "This is an old distrib"
loop: "{{ os_list }}"
loop_control:
label: "{{ item.ansible_distribution }}-{{ item.ansible_distribution_version }}"
when: (
item.ansible_distribution == "Amazon"
and
item.ansible_distribution_version == "2018.03"
)
or
(
item.ansible_distribution == "RedHat"
and
item.ansible_distribution_major_version == "6"
)
And the result
PLAY [Statements for checking old/recent distribs] ************************************************************************************************************************************************************************
TASK [Check conditions for recent distribs] *******************************************************************************************************************************************************************************
ok: [localhost] => (item=Amazon-(Karoo)) => {
"msg": "This is a recent distrib"
}
skipping: [localhost] => (item=Amazon-2018.03)
skipping: [localhost] => (item=RedHat-6.x)
ok: [localhost] => (item=RedHat-7.x) => {
"msg": "This is a recent distrib"
}
TASK [Check conditions for old distribs] **********************************************************************************************************************************************************************************
skipping: [localhost] => (item=Amazon-(Karoo))
ok: [localhost] => (item=Amazon-2018.03) => {
"msg": "This is an old distrib"
}
ok: [localhost] => (item=RedHat-6.x) => {
"msg": "This is an old distrib"
}
skipping: [localhost] => (item=RedHat-7.x)
PLAY RECAP ****************************************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
As you can see it does the job as expected. So either your data is not gathered correctly or your check the wrong values.
Note: When @Vladimir Botka asks for an MCVE in the comments, this is a typical example.
ansible_distribution, ansible_distribution_version, ansible_distribution_major_version
and also post the output. Generally make it mcve (or include a crystal ball). I downvoted because lacking an MCVE makes it hard to answer.