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
++++++++++++++++++++++++++++++++++

On Friday, June 21, 2019 at 3:13:31 AM UTC+8, Angel Rengifo Cancino wrote:
>
> Just one additional comment (if applicable):
>
> Would the "filebeat" binary require any environment variables to work 
> properly? Maybe you have some vars that are defined on your shell session, 
> but they're not defined within ansible execution context.
>
> On Thu, Jun 20, 2019 at 4:05 AM Dick Visser <[email protected] 
> <javascript:>> wrote:
>
>> Your privilege escalation logic doesn’t look right. Please read up on 
>> https://docs.ansible.com/ansible/latest/user_guide/become.html
>> More specifically don’t issue sudo as part of a command but instead use 
>> the ‘become’ logic of ansible. 
>>
>> Also what environment variables does this filebeat command expect?
>> Running things manually in an interactive shell usually exposes a 
>> different set of environment vars than the ansible shell/command module. 
>>
>> See 
>>
>> https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html
>>
>> Slightly related, the command uses a relative path so it could mean that 
>> it runs a different filebeat than what you’re using in an interactive 
>> shell. 
>>
>>
>> Dick 
>>
>>
>>
>>
>> On Thu, 20 Jun 2019 at 11:41, Prakash Sharma <[email protected] 
>> <javascript:>> wrote:
>>
>>> I am too facing this issue. 
>>>
>>> When I do manually in the server , works fine , but from ansible ( using 
>>> service module , command, shell , and even raw command ) it doesnt start .
>>>
>>> Has anyone seen this , if yes , any clue ?
>>>
>>>
>>>
>>> On Thursday, June 21, 2018 at 3:28:47 AM UTC+8, Daastan Pradhan wrote:
>>>>
>>>> I am running this task in ansible playbook. 
>>>> - name: Start filebeat service 
>>>>   shell: /fisc/uts/bin/sudo filebeat start 
>>>>
>>>> This doesnot start the filebeat agent. But I have checked manually 
>>>> running that command on the test servers. It works fine. ( I tried 
>>>> ‘command’ instead of ‘shell’, it doesnt work either) 
>>>>
>>>> The stop command works tho if I replace start with stop. But ‘start’ 
>>>> and ‘restart’ doesnt work.Can you please help?
>>>
>>> -- 
>>> 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 [email protected] <javascript:>.
>>> To post to this group, send email to [email protected] 
>>> <javascript:>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/ansible-project/d008e341-0ce6-4711-a3c0-0630086618a6%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/d008e341-0ce6-4711-a3c0-0630086618a6%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> -- 
>> Sent from a mobile device - please excuse the brevity, spelling and 
>> punctuation.
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/CAL8fbwNb-924Jgtq7VQPDkh5i3gWxFb4S%2BTKizMZtDoi3rjYRQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/CAL8fbwNb-924Jgtq7VQPDkh5i3gWxFb4S%2BTKizMZtDoi3rjYRQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0ae9c15c-d3e5-4c76-a6cb-116316e6fb20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to