--- - name: Convert grafana-server group name if exist ansible.builtin.add_host: name: "{{ item }}" groups: "{{ monitoring_group_name }}" ansible_host: "{{ hostvars[item]['ansible_host'] | default(omit) }}" ansible_port: "{{ hostvars[item]['ansible_port'] | default(omit) }}" with_items: "{{ groups.get((grafana_server_group_name | default('grafana-server')), []) }}" run_once: true