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

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!

On Tue, Oct 21, 2014 at 6:46 AM, MarcAnthony <[email protected]
> wrote:

>
> 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
>
> ---
> - hosts: all
>
>   tasks:
>
> #    - shell: echo "nested test a={{ item[0] }} b={{ item[1] }} c={{
> item[2] }}"
>     - shell: chkconfig --list {{ item[0] }}.{{ item[1] }}{{ item[2] }} >>
> /tmp/cmd.out
>       with_nested:
>         - [ 'jboss' ]
>         - [ 'jvm', 'wsas', 'tas', 'las', 'esas', 'scas']
>         - [ 1, 2, 3, 4, 5 ,6, 7, 8 ]
>       register: cmd_result
>       failed_when: "'error' in cmd_result.stderr"
>       ignore_errors: yes
>
>  (Psudeo)
>
>     When match
>     Template: src=/files/config/appserver.conf.j2
> dest=/etc/sysconfig/service.{{item}}.config
>      notifiy: restart {{ item[0] }}.{{ item[1] }}{{ item[2] }}
>
>     Handler:
>        - name=restart {{ item[0] }}.{{ item[1] }}{{ item[2] }}
>        - service: name={{ item[0] }}.{{ item[1] }}{{ item[2] }}
> state=restarted
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f2770d98-df6d-436a-ace2-5f14232171b6%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/f2770d98-df6d-436a-ace2-5f14232171b6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAMFyvFjhR%2Bvgwy0JDoMrP6HNzgmW0oqTKNVUuV31o0eJH-NADQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to