# Starting filebeat issue from ansible for RHL6

**URL:** <https://forum.ansible.com/t/starting-filebeat-issue-from-ansible-for-rhl6/27835>\
**Category:** Ansible Project\
**Created:** [June 20, 2018, 7:28pm UTC](https://forum.ansible.com/t/starting-filebeat-issue-from-ansible-for-rhl6/27835 "2018-06-20T19:28:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daastan\_Pradhan](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@Daastan\_Pradhan](https://forum.ansible.com/u/Daastan_Pradhan)\
**Post date:** [June 20, 2018, 7:28pm UTC](https://forum.ansible.com/t/starting-filebeat-issue-from-ansible-for-rhl6/27835/1 "2018-06-20T19:28:47Z")

</div>

I am running this task in ansible playbook.  
- name: Start filebeat service  
&nbsp;&nbsp;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?

---

<div class="post-metadata">

**Author:** ![iamlightsocialxen](https://avatars.discourse-cdn.com/v4/letter/i/ee59a6/32.png) [@iamlightsocialxen](https://forum.ansible.com/u/iamlightsocialxen)\
**Post date:** [June 20, 2019, 8:41am UTC](https://forum.ansible.com/t/starting-filebeat-issue-from-ansible-for-rhl6/27835/2 "2019-06-20T08:41:20Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 20, 2019, 9:04am UTC](https://forum.ansible.com/t/starting-filebeat-issue-from-ansible-for-rhl6/27835/3 "2019-06-20T09:04:48Z")

</div>

Your privilege escalation logic doesn’t look right. Please read up on  
[https://docs.ansible.com/ansible/latest/user\_guide/become.html](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](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

---

<div class="post-metadata">

**Author:** ![Angel\_Rengifo\_Cancin](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Angel\_Rengifo\_Cancin](https://forum.ansible.com/u/Angel_Rengifo_Cancin)\
**Post date:** [June 20, 2019, 7:13pm UTC](https://forum.ansible.com/t/starting-filebeat-issue-from-ansible-for-rhl6/27835/4 "2019-06-20T19:13:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iamlightsocialxen](https://avatars.discourse-cdn.com/v4/letter/i/ee59a6/32.png) [@iamlightsocialxen](https://forum.ansible.com/u/iamlightsocialxen)\
**Post date:** [June 21, 2019, 1:34am UTC](https://forum.ansible.com/t/starting-filebeat-issue-from-ansible-for-rhl6/27835/5 "2019-06-21T01:34:25Z")

</div>

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…

1. 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
