Is there a way to check if a service is already enabled on a linux machine?

41 views
Skip to first unread message

yaakov....@sparkpost.com

unread,
Aug 2, 2018, 3:11:51 PM8/2/18
to Ansible Project
I don't see a way to do it with service_facts, do I have to use shell magic?

Brian Coca

unread,
Aug 2, 2018, 6:04:12 PM8/2/18
to Ansible Project
You can use the appropriate service module:

- service: name=myservice enabled=yes
check_mode: true
register: isit

- fail: msg=its not enabled
when: isit is changed





--
----------
Brian Coca

yaakov....@sparkpost.com

unread,
Aug 3, 2018, 8:52:31 AM8/3/18
to Ansible Project
Awesome! Thanks!

YK

Adam Miller

unread,
Aug 3, 2018, 9:14:37 AM8/3/18
to ansible...@googlegroups.com
On Fri, Aug 3, 2018 at 7:52 AM yaakov.kuperman via Ansible Project
<ansible...@googlegroups.com> wrote:
>
> Awesome! Thanks!

As an option, you can also use the service_facts module to inspect
service state: https://docs.ansible.com/ansible/latest/modules/service_facts_module.html#service-facts-module

-AdamM
> --
> 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 post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b54af985-206c-4fe3-a5ad-a0286e2f27ff%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Pavel Cahyna

unread,
Aug 3, 2018, 9:24:42 AM8/3/18
to ansible...@googlegroups.com
On Fri, Aug 03, 2018 at 08:14:15AM -0500, Adam Miller wrote:
> On Fri, Aug 3, 2018 at 7:52 AM yaakov.kuperman via Ansible Project
> <ansible...@googlegroups.com> wrote:
> >
> > Awesome! Thanks!
>
> As an option, you can also use the service_facts module to inspect
> service state: https://docs.ansible.com/ansible/latest/modules/service_facts_module.html#service-facts-module

You can not, because the facts do not tell whether a service is enabled
or disabled.

P.

>
> -AdamM
>
> >
> > YK
> > On Thursday, August 2, 2018 at 6:04:12 PM UTC-4, Brian Coca wrote:
> >>
> >> You can use the appropriate service module:
> >>
> >> - service: name=myservice enabled=yes
> >> check_mode: true
> >> register: isit
> >>
> >> - fail: msg=its not enabled
> >> when: isit is changed
> >>
> >>
> >>
> >>
> >>
> >> --
> >> ----------
> >> Brian Coca
> >
> > --
> > 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 post to this group, send email to ansible...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b54af985-206c-4fe3-a5ad-a0286e2f27ff%40googlegroups.com.
> > 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAH-D1xd9HU8_jnGCWEH%3DkhtJqfQA8MtC_auJX9cao70FC3eG5Q%40mail.gmail.com.

yaakov....@sparkpost.com

unread,
Aug 3, 2018, 9:29:47 AM8/3/18
to Ansible Project
I was actually thinking of trying to change that, but I'm short on time.  Should I log a ticket or is that out of scope for the module?

I was also thinking about making it possible for service_facts to operate only on a single service, in order to save time on data collection. Same question - should I log something for that or is it out of scope?

Adam Miller

unread,
Aug 3, 2018, 9:43:39 AM8/3/18
to ansible...@googlegroups.com
On Fri, Aug 3, 2018 at 8:29 AM yaakov.kuperman via Ansible Project
<ansible...@googlegroups.com> wrote:
>
> I was actually thinking of trying to change that, but I'm short on time. Should I log a ticket or is that out of scope for the module?
>
> I was also thinking about making it possible for service_facts to operate only on a single service, in order to save time on data collection. Same question - should I log something for that or is it out of scope?

Please file an issue ticket, that's something the module should
probably be providing. I actually thought it did (which I'm apparently
mistaken on).

-AdamM
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9a9ff7f5-4714-437d-bff6-61f8913dc2ad%40googlegroups.com.

yaakov....@sparkpost.com

unread,
Aug 3, 2018, 9:54:54 AM8/3/18
to Ansible Project
Reply all
Reply to author
Forward
0 new messages