skip role if condition are not meet

hi
I need to skip a role in my playbook if a server doesn’t exist inside hosts file
hosts file:

[webserver]
server1.domain
server2.domain

[machine01]
server1.domain

[machine02]
server2.domain

play:

  • name: Scaling out the cluster
    hosts: webserver
    tags: scaleout
    roles:
  • scalingout

role:

tasks file for scalingoutcluster

  • name: Checking if there exist a cluster. If not, skip this tasks

when: scale_cluster == true

when: ‘inventory_secondary_node|string in group_names’

when: inventory_hostname == machine02

Can you try this?

  tasks:
  - name: Test1
    include_role:
      name: scaling_out
    when: some condition