I am looking to get list of Windows services that is running along with their state by using win_service_info
module – Gather information about Windows services.
---
- name: Service Status
hosts: test
gather_facts: yes
tasks:
- name: Create variable with services
set_fact:
service_names: []
- name: Get service info
ansible.windows.win_service_info:
name: USRJOB*
register: service_info
- name: Load variable
set_fact:
service_names: "{{ service_names }}" + {{ item }}
loop: "{{ service_info | community.general.json_query('services[*].name') }}"
- name: Print the Countries after adding element
debug: var=service_names
I couldn't load the variable service_names
with all the services, no idea on how to also show the state of the service on the same debug message.