Help with loop tasks Ansible

I have a trouble with my tasks and can’t find solution. Maybe u can help me) I need to loop this tasks if

“{{country_info_loop}} != {{region}}”

but if

“{{country_info_loop}} == {{region}}”

then stop it.

- name: Start Check…
block:
- name: Create a new Droplet
community.digitalocean.digital_ocean_droplet:
state: present
oauth_token: “{{oauth_token}}”
name: “{{drop_name}}”
size: s-1vcpu-1gb
region: “{{region}}”
image: “ubuntu-18-04-x64”
wait_timeout: 500
ssh_keys:
- “{{ ssh_public_key.data.ssh_key.id }}”
project: project01
tags: “{{tag}}”
register: my_droplet

# Retrieve geolocation data of a host’s IP address
- name: Get IP geolocation data
ansible.builtin.shell: whois {{ (my_droplet.data.droplet.networks.v4 | selectattr(‘type’, ‘equalto’, ‘public’)).0.ip_address | default(‘’, true) }} | grep Country
register: country_info
- set_fact:
country_info_loop: “{{country_info}}”

- name: Delete if not our region
community.digitalocean.digital_ocean_droplet:
state: absent
oauth_token: “{{oauth_token}}”
id: “{{ my_droplet.data.droplet.id }}”
project: project01
wait_timeout: 500
when: “{{country_info_loop}} != {{region}}”

include_tasks didn’t works with loop/until etc. Because loop can’t find my variables. And i don’t know how i can loop this all (

You’re making us assume a lot because we don’t know what ‘{{ my_droplet }}’ or '{{ region }}" looks like.
If I throw a public IP address that’s from near me (I’m in the United States) into ‘whois’, grep for ‘Country’ and register the result, I get the following.
- name: Get IP geolocation data
ansible.builtin.shell: whois ‘152.2.22.62’ | grep Country
register: country_info
# Drop this useless ‘set_fact’ task:
# - set_fact:
# country_info_loop: “{{country_info}}”

- name: show country_info
ansible.builtin.debug:
msg: “{{ country_info }}”

TASK [show country_info] ***********************************
ok: [localhost] => {
“msg”: {
“changed”: true,
“cmd”: “whois ‘152.2.22.62’ | grep Country”,
“delta”: “0:00:00.209917”,
“end”: “2023-01-30 06:53:46.436137”,
“failed”: false,
“msg”: “”,
“rc”: 0,
“start”: “2023-01-30 06:53:46.226220”,
“stderr”: “”,
“stderr_lines”: [],
“stdout”: “Country: US”,
“stdout_lines”: [
“Country: US”
]
}

}

Down below, you compare when: “{{country_info_loop}} != {{region}}”. As I said, we have no idea what region look like, but it’s extremely unlikely to look like the ‘msg’ above. At the very least, you’ll need to examine specific fields in your registered variable, something like “country_info[‘stdout_lines’]|first”. But that’s unlikely to be sufficient unless your ‘{{region}}’ also came from ‘whois’.

include_tasks can be made to work, but first you need to understand your own data.