I have a set of windows services and need to find out whether those services are running in the target windows host. If at least one of the services no running I need to start those services and need to set the start mode to auto.
- name: Check weather service is running or not
ansible.windows.win_service_info:
name: "{{ item }}"
register: win_service_info
with_items:
- BrokerInfrastructure #Background Tasks Infrastructure (BrokerInfrastructure) Service
- DcomLaunch #DCOM Server Process Launcher Service
- gpsvc #Group Policy Client Service
- name: Start the services
ansible.windows.win_service:
name: << don't know how to write this part >>
start_mode: auto
state: started
register: service_startup
with_items: "{{ win_service_info.results }}"
when: << don't know how to write this part >>