When condition help - Skip if service running

41 views
Skip to first unread message

Nitrous

unread,
Aug 26, 2022, 10:17:12 AM8/26/22
to Ansible Project
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.

Paul Manno

unread,
Aug 26, 2022, 10:22:37 AM8/26/22
to ansible...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2ee1702e-48eb-4cde-b8d4-5bcc181b2443n%40googlegroups.com.

Nitrous

unread,
Aug 26, 2022, 10:27:53 AM8/26/22
to Ansible Project
Thanks, but I have other tasks that depend on my when condition, so I need to get it right.

Nitrous

unread,
Aug 26, 2022, 11:53:46 AM8/26/22
to Ansible Project
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.



Rowe, Walter P. (Fed)

unread,
Aug 26, 2022, 11:59:12 AM8/26/22
to ansible...@googlegroups.com
Please read the module page for a description of what is "registered" with win_service.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Nitrous

unread,
Aug 26, 2022, 12:13:01 PM8/26/22
to Ansible Project
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

Rowe, Walter P. (Fed)

unread,
Aug 26, 2022, 12:21:59 PM8/26/22
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
Reply all
Reply to author
Forward
0 new messages