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 !
Run the Ansible command with -vvvv and post the
output.
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 !!
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_S1
(Sudheer S)
February 11, 2019, 9:47am
5
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.
Did you put become_user to root when you try with become: yes ?
Regards,
JYL
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
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 ?
Because this task works:
command: /home/…/…/nginx stop
but i want a syntax ansible.
Thx for answer guy !!