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?
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 ?
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
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.
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 ,
- 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…
- 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