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. On Friday, January 27, 2023 at 5:49:05 AM UTC-5 voishunter wrote: > <https://stackoverflow.com/posts/75256471/timeline> > > 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 > <http://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('<none>', 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 > <http://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 received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bd373038-0f39-4398-9e2b-1f11e590e7d0n%40googlegroups.com.