[Software]

Installation von NXLog auf Windows mit Ansible

/installation-von-nxlog-auf-windows-mit-ansible
Installation von NXLog auf Windows mit Ansible

In diesem Blogbeitrag zeige ich Dir, wie Du NXLog auf einem Windows-Rechner mittels Ansible installierst.
Ansible ist ein starkes Tool zur Automatisierung von Aufgaben auf mehreren Rechnern und spart viel Zeit und Aufwand.
Wir verwenden ein Playbook, das den kompletten Installationsprozess abdeckt.


Voraussetzungen

Bevor Du beginnst, stelle sicher, dass folgende Voraussetzungen erfüllt sind:

  • Ansible ist auf dem Control Node installiert
  • WinRM ist auf dem Windows-Rechner eingerichtet und erreichbar
  • Die NXLog-MSI-Datei liegt auf dem Control Node
  • Eine gültige nxlog.conf ist vorhanden
  • Der Windows-Host ist im Ansible-Inventory eingetragen

Playbook-Übersicht

Hier ist das Playbook, das wir verwenden:

---
# Install software on Windows using Ansible
- name: Install software on Windows
  hosts: all
  vars:
    msi_source_path: "/nxlog.msi"  # Source path of the MSI file on the control machine
    msi_dest_path: "C:\\temp\\nxlog.msi"  # Destination path for the MSI file on the Windows machine
    nxlog_conf_source_path: "/nxlog.conf"  # Source path of the nxlog configuration file on the control machine
    nxlog_conf_dest_path: "C:\\Program Files\\nxlog\\conf\\nxlog.conf"  # Destination path for the nxlog configuration file on the Windows machine

  tasks:
    - name: Ensure C:\temp directory exists
      win_file:
        path: C:\temp
        state: directory

    - name: Copy MSI file to Windows machine
      win_copy:
        src: "{{ msi_source_path }}"
        dest: "{{ msi_dest_path }}"

    - name: Install MSI package
      win_package:
        path: "{{ msi_dest_path }}"
        state: present

    - name: Create destination directory for nxlog.conf if it doesn't exist
      win_file:
        path: "C:\\Program Files\\nxlog\\conf"
        state: directory

    - name: Copy nxlog.conf to Windows machine
      win_copy:
        src: "{{ nxlog_conf_source_path }}"
        dest: "{{ nxlog_conf_dest_path }}"

    - name: Restart nxlog service
      win_service:
        name: nxlog
        state: restarted
````

---

## Schritt-für-Schritt-Anleitung

### 1. Verzeichnis erstellen

Zuerst stellt das Playbook sicher, dass das Verzeichnis `C:\temp` auf dem Windows-Rechner existiert.
Dorthin wird später die MSI-Datei kopiert.

```yaml
- name: Ensure C:\temp directory exists
  win_file:
    path: C:\temp
    state: directory

2. MSI-Datei kopieren

Die MSI-Datei wird vom Control Node auf den Windows-Rechner nach C:\temp kopiert.

- name: Copy MSI file to Windows machine
  win_copy:
    src: "{{ msi_source_path }}"
    dest: "{{ msi_dest_path }}"

3. MSI-Paket installieren

Ansible installiert nun das MSI-Paket auf dem Windows-Rechner.

- name: Install MSI package
  win_package:
    path: "{{ msi_dest_path }}"
    state: present

4. Konfigurationsverzeichnis erstellen

Falls das Verzeichnis für die NXLog-Konfigurationsdatei noch nicht existiert, wird es angelegt.

- name: Create destination directory for nxlog.conf if it doesn't exist
  win_file:
    path: "C:\\Program Files\\nxlog\\conf"
    state: directory

5. Konfigurationsdatei kopieren

Die nxlog.conf wird vom Control Node auf den Windows-Rechner kopiert.

- name: Copy nxlog.conf to Windows machine
  win_copy:
    src: "{{ nxlog_conf_source_path }}"
    dest: "{{ nxlog_conf_dest_path }}"

6. NXLog-Service neu starten

Zum Abschluss wird der NXLog-Service neu gestartet, damit die neue Konfiguration aktiv wird.

- name: Restart nxlog service
  win_service:
    name: nxlog
    state: restarted

Ausführung des Playbooks

Speichere das Playbook z. B. als install_nxlog.yml und führe es mit folgendem Befehl aus:

ansible-playbook -i <Dein Inventory File> install_nxlog.yml

Stelle sicher, dass Dein Inventory den Windows-Host korrekt enthält und die Verbindung über WinRM funktioniert.


Mit diesem Playbook kannst Du NXLog schnell und sauber auf Windows installieren und konfigurieren.
Viel Erfolg bei der Automatisierung!

Anzeige

/comments0 Einträge

Kommentare

> NO_COMMENTS_FOUND

> INITIATE_COMMENT_PROTOCOL

MARKDOWN_SUPPORT: ENABLED
CHARS: 0