Score:1

Ansible - I need to check given services are running in target windows host and if not running need to start the service

cn flag

First, I check the list of windows process are running and collect the output into a register variable. next I need to start the service which are not running based on the above output(register).

- 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: run services
    ansible.windows.win_service:
      name: << don't know how to write >>
      start_mode: auto
      state: started
    register: service_startup 
    with_items: "{{ win_service_info.results }}"
    when: << i don't know how to write >>
Score:4
br flag

You don't need to check whether the service is running in the use case you describe. Just tell Ansible you want the services to be enabled and running as the end-state. In other words, remove the first block and use only the second:

- name: run services
  ansible.windows.win_service:
    name: "{{ item }}"
    start_mode: auto
    state: started
  with_items:
    - BrokerInfrastructure #Background Tasks Infrastructure (BrokerInfrastructure) Service
    - DcomLaunch #DCOM Server Process Launcher Service
    - gpsvc #Group Policy Client Service
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.