When condition help - Skip if service running

Im trying to figure out a way, on how to make a condition exit, if a service is running.
If it isnt running, then install it.

My play book looks like below:

  • name: Check if LogRhythm System Monitor service is installed
    win_service:
    name: lg
    register: lg

  • ansible.builtin.debug:
    #msg: “state: running found”
    var: lg
    #verbosity: 4
    when: lg is search(“runing”)

I purposely used the variable “runing” instead of “running”, as for new server builds, the service isnt installed and running, so it will install it.

But if the service is “running”, how can I modify my existing when condition to skip, if service is “running”?

Thanks.

https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_service_info_module.html

Thanks, but I have other tasks that depend on my when condition, so I need to get it right.

How can I search for this exact string using my example:

“exists”: true

My when condition:

when: lg is search( “exists”: true )

It errors out using “exists”: true.

Please read the module page for a description of what is “registered” with win_service.

Walter

Yes, its the same information I gathered previously.
I need to search for this string in my when condition:

“exists”: true

How can I do that?

Thanks

Think it through … what is the structure of the data in ‘lg’ after win_service? You have to learn to decipher structured data so you can learn how to reference it.

Walter