Need help for a Playbook to collecting logs from different Servers +

Hi there!

I wanna create an playbook with which I can get Logs from Hosts of our three different Stages and there from the concerned service (webserver, jobserver or report)

Our Inventory-File is the following:

#################
## Host-Part
#################

# TUI-Hosts

# Company1
[iuvr490]
iuvr490.in.domain.company

[iuvr491]
iuvr491.in.domain.company

[iuvr492]
iuvr492.in.domain.company

# Company2
[iuvp297]
iuvp297.in.domain.company

[iuvp299]
iuvp299.in.domain.company

[iuvp300]
iuvp300.in.domain.company


# PreLive-Hosts

# Company1
[iuvr487]
iuvr487.in.domain.company

[iuvr488]
iuvr488.in.domain.company

[iuvr489]
iuvr489.in.domain.company

[iuvr493]
iuvr493.in.domain.company

[iuvr494]
iuvr494.in.domain.company

[iuvr495]
iuvr495.in.domain.company

# Company2
[iuvp402]
iuvp402.in.domain.company

[iuvp403]
iuvp403.in.domain.company

[iuvp404]
iuvp404.in.domain.company

[iuvp405]
iuvp405.in.domain.company

[iuvp406]
iuvp406.in.domain.company

[iuvp407]
iuvp407.in.domain.company


# Live-Hosts

# Company1
[iuvr481]
iuvr481.in.domain.company

[iuvr482]
iuvr482.in.domain.company

[iuvr483]
iuvr483.in.domain.company

[iuvr484]
iuvr484.in.domain.company

[iuvr485]
iuvr485.in.domain.company

[iuvr486]
iuvr486.in.domain.company

# Company2
[iuvp396]
iuvp396.in.domain.company

[iuvp397]
iuvp397.in.domain.company

[iuvp398]
iuvp398.in.domain.company

[iuvp399]
iuvp399.in.domain.company

[iuvp400]
iuvp400.in.domain.company

[iuvp401]
iuvp401.in.domain.company


#################
## Service-Part
#################

# Company1 TUI Service-Part

[Company1_tui_webserver:children]
iuvr490

[Company1_tui_job:children]
iuvr491

[Company1_tui_report:children]
iuvr492

[Company1_tui:children]
Company1_tui_report
Company1_tui_job
Company1_tui_webserver


# Company1 PreLive Service-Part

[Company1_prelive_webserver:children]
iuvr494
iuvr495

[Company1_prelive_job:children]
iuvr488
iuvr489

[Company1_prelive_report:children]
iuvr487
iuvr493

[Company1_prelive:children]
Company1_prelive_report
Company1_prelive_job
Company1_prelive_webserver


# Company1 Live Service-Part

[Company1_live_webserver:children]
iuvr483
iuvr484

[Company1_live_job:children]
iuvr481
iuvr482

[Company1_live_report:children]
iuvr485
iuvr486

[Company1_live:children]
Company1_live_report
Company1_live_job
Company1_live_webserver


# Company2 TUI Service-Part

[Company2_tui_webserver:children]
iuvp297

[Company2_tui_job:children]
iuvp299

[Company2_tui_report:children]
iuvp300

[Company2_tui:children]
Company2_tui_report
Company2_tui_job
Company2_tui_webserver


# Company2 PreLive Service-Part

[Company2_prelive_webserver:children]
iuvp404
iuvp405

[Company2_prelive_job:children]
iuvp402
iuvp403

[Company2_prelive_report:children]
iuvp406
iuvp407

[Company2_prelive:children]
Company2_prelive_report
Company2_prelive_job
Company2_prelive_webserver


# Company2 Live Service-Part

[Company2_live_webserver:children]
iuvp397
iuvp400

[Company2_live_job:children]
iuvp399
iuvp401

[Company2_live_report:children]
iuvp396
iuvp398

[Company2_live:children]
Company2_live_report
Company2_live_job
Company2_live_webserver


#################
## Operation-Part
#################

# Company2 Server for creating nfs forder structure

[Company2_tui_nfs:children]
iuvp297

[Company2_prelive_nfs:children]
iuvp404

[Company2_live_nfs:children]
iuvp397

[Company2_nfs:children]
Company2_tui_nfs
Company2_prelive_nfs
Company2_live_nfs


# Company1 Server for creating nfs forder structure

[Company1_tui_nfs:children]
iuvr490

[Company1_prelive_nfs:children]
iuvr494

[Company1_live_nfs:children]
iuvr483

[Company1_nfs:children]
Company1_tui_nfs
Company1_prelive_nfs
Company1_live_nfs

###################
## Deployment-Part
###################

# Deployment of the Company2 Server

[Company2_live_p1:children]
iuvp397
iuvp399
iuvp396

[Company2_live_p2:children]
iuvp400
iuvp401
iuvp398

[Company2_prelive_q1:children]
iuvp404
iuvp403
iuvp406

[Company2_prelive_q2:children]
iuvp405
iuvp402
iuvp407


#################
## All Company1-Hosts
#################

[Company1:children]
Company1_tui
Company1_prelive
Company1_live


###################
## All Company2-Hosts
###################

[Company2:children]
Company2_tui
Company2_prelive
Company2_live

The Logs are located as followed on the three different service hosts (webserver, jobserver or report):

Webserver:

Application-Logs:
- /vol1/webserver/Logs/

Container-Logs:
- /vol1/podman/logs/

Jobserver:

Application-Logs:
- /vol1/jobserver/Logs/

Container-Logs:
- /vol1/podman/logs/

Reportserver:

Application-Logs:
- /vol1/reportserver/Logs/

Container-Logs:
- /vol1/podman/logs/

How can I create an Playbook that does the following tasks:

  • Go in the corresponding directory (/vol1/webserver/Logs/ OR /vol1/jobserver/Logs/ OR /vol1/reportserver/Logs/) and copies all Logs to /tmp for example

  • ZIP all logs on /tmp (gzip -9) put at the beginning on every file the Hostname (FQDN)

  • Move all zipped Log Files from /tmp via rsync or scp to an other host

  • delete every Log File from /tmp

The Playbook should be able to recognise when I wanna have Logs from Jobserver or from an Webserver.
Depending on that it should do the above tasks on the corresponding host.

Hope you can help me,
thanks :slight_smile:

You know which steps you want to take, so how have you so far attempted to solve the problem?

Hints: you might want to look at the documentation for archive and fetch.

Seems like a good use case for Inventory Group Variables to me, if your server falls into the “jobserver” group then it looks in the applicable Application or Container Logs location, if it’s in another group like Reportserver then it can have a different specified location for those files…

## Host-Part
#################

# TUI-Hosts

# Company1
[iuvr490]
iuvr490.in.domain.company

# Company2
[iuvp297]
iuvp297.in.domain.company

# PreLive-Hosts

# Company1
[iuvr487]
iuvr487.in.domain.company

# Company2
[iuvp402]
iuvp402.in.domain.company

specify a couple of groups in your Inventory files with jobservers bundled together under a group and then in your group_vars specify the location of those files for those servers…

How to build your inventory — Ansible Community Documentation

[jobserver]
iuvr490
iuvr487

[jobserver:vars]
halon_system_timeout=30
self_destruct_countdown=60
escape_pods=2
application-logs=/vol1/jobserver/logs/
container-logs=/vol1/podman/logs/

Apologies in advance. This is the kind of answer I generally don’t like in a domain-specific context, but I’m going to be “That Guy” this time and say it: You’re solving the wrong problem. You certainly can create a role-your-own log aggregation automation solution in Ansible. And as a stop-gap, temporary solution it may be a reasonable thing to do. But for the long term, you should be looking at some of the free and commercial log aggregation solutions out there. Just google “log aggregation tools”. There are lots of tools readily available that do this better than what you’re going to come up with.

And you still get to use Ansible to deploy and configure them!

And now, back to your on-topic posts…