How to continuously tail remote files using ansible?
Asked Answered
A

3

12

How is it possible to tail a file located at several remote servers in a known location using ansible? This question is based on this comment on this Hacker News thread:

In my company, we have hundred machines and tailing done with ansible. If we want customize the log view, we can simply edit the playbook. I think it is very handy compared to we need additional npm package (and not to mention additional effort for customization).

Agatha answered 12/11, 2015 at 2:21 Comment(3)
Ansible just runs ssh commands, so I imagine having a shell command running tail over the hosts in your inventory file would work. I'll let someone answer with an official response, thoughPorky
This is a fundamentally wrong approach. You are using a shovel to paint your walls. While you might be able to cobble something together using Ansible, it's not the right tool for this job. You should be using a log aggregation/centralized logging system.Valentijn
Sure, the proper way would indeed be to spend time on a log aggregation/centralized logging system. However, I am looking for a quick and dirty solution to tail logs from multiple servers without having to set up multiple terminal panes where each pane is tailing the logs from a single remote server.Agatha
P
4

You can use ansible ad-hoc :

 ansible atlanta -a "tail /homedir/myfile" -f 10

UPDATE

Ansible can only print the output after completing the command. That's why I think what you want is not possible, ansible is probably not the tool you want for this job. Check issue 4870 and 3887.

If you really want to use ansible to do this, there is hack posted in one of issues (haven't tested and actually I don't recommend it).

I really don't know what the guy from HN was talking about, maybe just tail (without the -f)?

Pollen answered 12/11, 2015 at 2:25 Comment(1)
I need to continuously monitor the logs using "tail -f"Agatha
S
0

In the past, I've used capistrano to build tasks that would tail and follow logs on multiple hosts and output interactively. If you're okay with Ruby, I know this will work. If you want to stick with Python, fabric is your thing and see other people have done this with it.

Statistical answered 3/10, 2016 at 13:1 Comment(1)
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.Hays
P
0

You can use daggy for streaming commands via ssh, including tail -f

Peri answered 3/5, 2020 at 19:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.