# service name=custom.service1 state=present ???

**URL:** <https://forum.ansible.com/t/service-name-custom-service1-state-present/16571>\
**Category:** Ansible Project\
**Created:** [October 21, 2014, 1:46pm UTC](https://forum.ansible.com/t/service-name-custom-service1-state-present/16571 "2014-10-21T13:46:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcAnthony](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@MarcAnthony](https://forum.ansible.com/u/MarcAnthony)\
**Post date:** [October 21, 2014, 1:46pm UTC](https://forum.ansible.com/t/service-name-custom-service1-state-present/16571/1 "2014-10-21T13:46:26Z")

</div>

Hello

I have a bunch of custom services linked to a service aka jbossas

eg.

chkconfig --list | grep jboss  
jboss.jvm1 0:off 1:off 2:off 3:off 4:off 5:off 6:off  
jboss.jvm2 0:off 1:off 2:off 3:off 4:off 5:off 6:off

Is there a way with Ansilbe to check for the existence of a service ie. jboss.jvm[1-8] if conditional do X

I have tried with nested\_loops but this looks seems extremely ineffeciant to connect and check for each of the possible 48 services for each node in ansible.

ideally a state=present in the service module would be great to use in a scnearios where you need to query a bunch of nodes to find a particular service and aka, patch or change a config based on its presence

Example

Playbook

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [October 23, 2014, 3:41pm UTC](https://forum.ansible.com/t/service-name-custom-service1-state-present/16571/2 "2014-10-23T15:41:10Z")

</div>

Hi Marc,

I would recommend writing a custom fact to deploy on each system, which could return a list of the services installed on that system. Unfortunately, you’re still going to have to pre-define each handler, as they cannot be defined in a loop themselves (as you have it in your pseudo code).

See the documentation here on writing custom (local) facts: [http://docs.ansible.com/playbooks\_variables.html#local-facts-facts-d](http://docs.ansible.com/playbooks_variables.html#local-facts-facts-d)

Alternatively, you could use the stat module to determine if the init file for each service name is present, and then use that as the basis for your tests/loops. The caveat regarding the handlers still applies, however.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![MarcAnthony](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@MarcAnthony](https://forum.ansible.com/u/MarcAnthony)\
**Post date:** [October 23, 2014, 6:58pm UTC](https://forum.ansible.com/t/service-name-custom-service1-state-present/16571/3 "2014-10-23T18:58:37Z")

</div>

James

That is very helpful thanks for the direction.
