Your question is somehow vague and unspecific. However, parts of your question could be answered with the following approach.
According your description
How to check for group of services with common part of name?
I understand that you like to check the service on a server only if a server belongs to certain group of hosts or domain in your inventory file (and if "services" are organized structured in inventory).
---
- hosts: test
become: true
gather_facts: true
tasks:
- name: Gathering Service Facts
service_facts:
when: "'test' in group_names and 'www.example.com' in ansible_domain"
- name: Show result
debug:
var: services
resulting into an output of
TASK [Gathering Facts] *************
ok: [db.example.com]
ok: [www.example.com]
TASK [Gathering Service Facts] *****
ok: [www.example.com]
TASK [Show result] *****************
ok: [db.example.com] =>
services: VARIABLE IS NOT DEFINED!
ok: [www.example.com] =>
services:
...
Further Q&A
According your question
Ansible service_facts
filtering by partial name
if you want to check for results ... from list of services using Ansible you may have a look into the linked answered or
Further Q&A
If all the information and links here do not answer your question you may need to provide much more information and description about your use case.