How to iterate Ansible Inventory

I appreciate your answers. Yes, I didn't realize that Ansible by default to take all hosts declarated in the inventory.

I share my ansible code with you. It works:

---
  • name: Play to connect by ssh  hosts: ium  gather_facts: False  tasks:    - name: iterate      wait_for:        host: "{{ ansible_host }}"        port: "{{ item.value }}"        timeout: 1        state: started        delay: 0      loop: "{{ port | dict2items }}"

  • name: Play to connect to servers with ssh problems  hosts: ium_without_ssh  gather_facts: False  tasks:    - name: iterate      shell:        cmd: nc -zv "{{ real_ip }}" "{{ item.value }}" -w 5      loop: "{{ port | dict2items }}"

Inventory:

---

ium:  hosts:    ithsso1aama:      ansible_host: 10.x.x.x      port:        AM_OID_A01: 9000        AM_OID_A02: 9010        AM_CBL_A01: 9070

  vars:

     ansible_user: test1      ansible_password: test1      ansible_ssh_common_args: -o HostKeyAlgorithms=+ssh-dss

ium_without_ssh:  hosts:    ithsso1aamb:      real_ip: 192.x.x.x      port:        AM_OID_B01: 9000        AM_OID_B02: 9010  vars:      ansible_host: 10.x.x.x      ansible_user: test1      ansible_ssh_common_args: -o HostKeyAlgorithms=+ssh-dss      ansible_password: test1

Thanks for your time.

/r/ansible Thread