service module doesnt work

28 views
Skip to first unread message

Gaurav1212

unread,
Jul 22, 2017, 3:38:11 AM7/22/17
to Ansible Project
Hi,

I am trying to restart the cron and httpd services, but unable to do so with ansible.

Output shows OK, but changed=0. See below output.

[root@slc09vev ansible]# ansible-playbook restart.cron.pb.yml

PLAY [This is to call the restart_cron role] ***********************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************
ok: [slc11zrn]
ok: [slc09vev]

PLAY RECAP *********************************************************************************************************************************************************
host1                   : ok=1    changed=0    unreachable=0    failed=0
host2                   : ok=1    changed=0    unreachable=0    failed=0


Here is my task file:

[root@slc09vev ansible]# cat roles/restart_cron/tasks/cron_restart.yml
 - name:"restart crond service"
 - service:
     name:crond state:restarted

What could be the reason for this?

Branko Majic

unread,
Jul 22, 2017, 4:50:59 AM7/22/17
to ansible...@googlegroups.com
Your task is never executed, you can see that in the output (there is
no mention whatsoever of "restart crond service").

Additionally, the task as you have output it here would never run
because of syntax errors (even if you had it correctly included) -
because it's not valid yaml. It would need to look something similar
to (note the spaces and newlines):

- name: "restart crond service"
- service:
name: crond
state: restarted

Best regards

--
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

Brian Coca

unread,
Jul 24, 2017, 9:11:27 AM7/24/17
to Ansible Project
Your syntax is invalid:

- name:"restart crond service"
- service:
name:crond state:restarted

You never get to the service task as you have an 'empty task' with
just the name ... and then you structure yaml format as it were k=v,
you probably want the following:

- name:"restart crond service"
service:
name: crond
state: restarted

or

- name:"restart crond service"
service: name=crond state=restarted


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

Mike Eriksson

unread,
Jul 25, 2017, 7:21:44 AM7/25/17
to Ansible Project
Gaurav,

It doesn't look like the 'restart crond service' tasks runs at all - how are you calling it from the 'restart.cron.pb.yml' playbook?

I believe that the OK you get is from the 'Gathering Facts' task since that's all that looks like it's running.

Cheers, Mike

--
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/2934fc02-1d0d-47eb-8228-83345842e142%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages