win_service_info register

185 views
Skip to first unread message

jer...@gmail.com

unread,
Jan 24, 2021, 8:08:28 AM1/24/21
to Ansible Project
Hi
Trying to use win_service_info with a register.
While the register is filled with multiple entries, i want to make sure all these are started.
How to write the loop ?

  - name: Find all services that start with 'blabla'
    ansible.windows.win_service_info:
      name: blabla*
    register: service

#Print everything
  - name: Print service facts
    ansible.builtin.debug:
      var: service

#Print only the first one 
  - name: Print service facts
    ansible.builtin.debug:
      var: service.services[0].name

  - name: make sure service is started
    win_service:
      name: 'service.services[{{ item }}].name'
      state: started
    with_items: service.services.index ?

Thanks!

cc @jborean93

Jeremie Levy

unread,
Jan 24, 2021, 8:44:26 AM1/24/21
to ansible...@googlegroups.com, jbor...@gmail.com
Hi Jordan, can you please assist here ?

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/iWsksxxaAaY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/00316553-786f-4d4b-96c8-abc85726cfebn%40googlegroups.com.

jbor...@gmail.com

unread,
Jan 24, 2021, 2:27:51 PM1/24/21
to Ansible Project
Just loop the services entry and then your item is item.name.

- win_service:
    name: '{{ item.name }}'
    state: started
  with_items: '{{ service.services }}'

This works because service.services is a list that contains a dictionary so you are looping each entry and then getting the name key in that dict.

Jeremie Levy

unread,
Jan 25, 2021, 6:53:03 AM1/25/21
to ansible...@googlegroups.com
Thank you!
I wonder why i didn't try it...

ftpk...@gmail.com

unread,
Sep 29, 2022, 8:40:50 PM9/29/22
to Ansible Project
HI Jordan,

I am wondering how I could modify the above code to only start when a service exist with out ignoring errors as an option.

Reply all
Reply to author
Forward
0 new messages