Thanks for you inputs guys ..
I too think it is missing some kind of environment variable when passed via ansible. Today morning I have tried investigate further and found that ,
1. If I manually try to restart filebeat service with root user in the server or over SSH , file beat service starts normally..
for e.g
ssh dev-bozo21 service filebeat restart
Or
[root@dev-bozo21 ~]# service filebeat restart
works fine..
2. But I run my ansible as non root user and have enabled sudo permission for that .. So starting filebeat over SSH via non root user (lets say devans) doesnt work
ssh -t devans@dev-bozo21 sudo /etc/init.d/filebeat restart >>> Dont work
But when I ssh to dev-bozo21 and then try to start the filebeat , this works
[devans@dev-bozo21 ~]$ sleep 5 ; sudo /etc/init.d/filebeat restart >>>>>>>> Works perfectly fine.
I am wondering why "ssh -t devans@dev-bozo21 sudo /etc/init.d/filebeat restart" ( I am sure ansible also tries something similar) doesn't work.
my code
+++++++++++++++++++++++++++++
---
- hosts: "{{ target }}"
become: yes
become_method: sudo
gather_facts: yes
(( Do some work ))
- name: restart filebeat
service:
name: filebeat
state: restarted
enabled: true
++++++++++++++++++++++++++++++++++