ansible service not work but command work

56 views
Skip to first unread message

ryad9...@gmail.com

unread,
Feb 8, 2019, 11:16:59 AM2/8/19
to Ansible Project
Hi,

When i use service in ansible same this task :

- name: "stop nginx"
  service:
      name: nginx
      state: stopped

Same with "become: yes" and "pattern: my_pattern_file"

but with line "command: sudo systemctl stop nginx"   it's working !! WHY ?

Thanks you for you answers guy ! :)

Stefan Schmid

unread,
Feb 8, 2019, 12:35:23 PM2/8/19
to Ansible Project
Run the Ansible command with -vvvv and post the
output.

ryad9...@gmail.com

unread,
Feb 11, 2019, 4:01:25 AM2/11/19
to Ansible Project
So,

When I run my playbook with this task :

- name: "stop nginx"
  service:
      name: nginx
      state: stopped

I have this message :

changed: [edeefreffe] => {"changed": true, "msg": "Service nginx not found on host, assuming it will exist on full run"}

but with this command ansible it's work :

- name: "Arret du nginx"
  command: sudo systemctl stop nginx

Someone have a answer please ??!

Thanks you very much !! :)

ryad9...@gmail.com

unread,
Feb 11, 2019, 4:17:50 AM2/11/19
to Ansible Project
And this same task in handler works :

- name: "stop nginx"
  service:
      name: nginx
      state: stopped

It's very strange, i think that it's bug in ansible ?

Sudheer S

unread,
Feb 11, 2019, 4:48:06 AM2/11/19
to ansible...@googlegroups.com


On 11/02/19 2:31 PM, ryad9...@gmail.com wrote:
So,

When I run my playbook with this task :

- name: "stop nginx"
  service:
      name: nginx
      state: stopped

I have this message :

changed: [edeefreffe] => {"changed": true, "msg": "Service nginx not found on host, assuming it will exist on full run"}

What happens when you use:

- name: "stop nginx"
  systemd:
      name: nginx
      state: stopped

I see that you are using `systemctl` in the command module but using `service` module in the task. Change it to systemd like above and tell us what happens.
-
Sudheer


but with this command ansible it's work :

- name: "Arret du nginx"
  command: sudo systemctl stop nginx

Someone have a answer please ??!

Thanks you very much !! :)


Le vendredi 8 février 2019 17:16:59 UTC+1, ryad9...@gmail.com a écrit :
Hi,

When i use service in ansible same this task :

- name: "stop nginx"
  service:
      name: nginx
      state: stopped

Same with "become: yes" and "pattern: my_pattern_file"

but with line "command: sudo systemctl stop nginx"   it's working !! WHY ?

Thanks you for you answers guy ! :)
--
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/35f9bd5f-5743-417f-b449-905e092828a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jean-Yves LENHOF

unread,
Feb 11, 2019, 5:15:29 AM2/11/19
to ansible...@googlegroups.com, ryad9...@gmail.com
Did you put become_user to root when you try with become: yes ?

Regards,

JYL

ryad9...@gmail.com

unread,
Feb 11, 2019, 5:19:43 AM2/11/19
to Ansible Project

What happens when you use:

- name: "stop nginx"
  systemd:
      name: nginx
      state: stopped

==> It's the same problem, the message error is :

changed: [edeefreffe] => {"changed": true, "msg": "Service nginx not found on host, assuming it will exist on full run"}
Same in specify become or become_user

ryad9...@gmail.com

unread,
Feb 11, 2019, 5:44:37 AM2/11/19
to Ansible Project
New probleme:

When i run this task it's works :

- name: "stopper nginx"
  systemd:
      name: /my_pattern/nginx
      state: stopped

But there is a warning message:

[WARNING]: The service (my_pattern/nginx) is actually an init script but the system is
managed by systemd

It's normaly ?

Le vendredi 8 février 2019 17:16:59 UTC+1, ryad9...@gmail.com a écrit :

Sudheer S

unread,
Feb 11, 2019, 11:47:38 AM2/11/19
to ansible...@googlegroups.com


On 11/02/19 4:14 PM, ryad9...@gmail.com wrote:
New probleme:

When i run this task it's works :

- name: "stopper nginx"
  systemd:
      name: /my_pattern/nginx
      state: stopped

But there is a warning message:

[WARNING]: The service (my_pattern/nginx) is actually an init script but the system is
managed by systemd

It's normaly ?

Why did you change

name: nginx

to /my_pattern/nginx

?


--
Sudheer Satyanarayana

ryad9...@gmail.com

unread,
Feb 11, 2019, 12:09:27 PM2/11/19
to Ansible Project
Because this task works:

command: /home/.../.../nginx stop

but i want a syntax ansible.

Thx for answer guy !! :)
Reply all
Reply to author
Forward
0 new messages