Running roles for every host mentioned in inventory file

HI ,

I have my inventory file like below , where I am using the variables primaryNode, secondaryNode in the roles so that particular role will run on the host specified infront of ansible_host values.

Now, how can i pass multiple hosts in the inventory under secondaryNode so that role2 will run on all those nodes one by one. and I will not need to create role3 or role 4 for those.

inventory file

all:
children:
ha:
hosts:
primaryNode:
ansible_host: domain.net1
secondaryNode:
ansible_host: domain.net2

my yaml looks liike elow :

23456789101112131415161718192021222324

---- name: Installing primary node  hosts: primaryNode  become: True  roles:
      - role: role1
- name: Installing secondary node  hosts: secondaryNode  become: True  roles:
      - role: role2

I think its not possible to pass multiple values to “ansible_host” variable . You can create “group” in inventory file with all the hosts listed under it.

Thanks
Neha Pithadiya.

Not sure if it's possible with ansbile but with Salt you can set Grains and do if else statements based on those grains

{% if role[host1] }
- role: host1
{% elif role[hoat2] %}
-role: host 2
{%endif%}

I would look up condition s for ansible

Don't know about virtual grains, but you can apply when: conditions

- role: role1
  when: "'role1' in group_names"

Regards
       Racke