Blog

Installing NXLog on Windows with Ansible

4/23/2025 3 min read
Installing NXLog on Windows with Ansible

In this blog post, I'll show you how to install NXLog on a Windows machine using Ansible.
Ansible is a powerful tool for automating tasks across multiple machines, saving you a lot of time and effort.
We will use a playbook that covers the entire installation process.


Prerequisites

Before you start, make sure the following prerequisites are met:

  • Ansible is installed on the control node
  • WinRM is set up and accessible on the Windows machine
  • The NXLog MSI file is available on the control node
  • A valid nxlog.conf configuration file is present
  • The Windows host is listed in the Ansible inventory

Playbook Overview

Here is the playbook we will use:

---
# 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

Step-by-Step Guide

1. Create Directory

First, the playbook ensures the directory C:\temp exists on the Windows machine. This is where the MSI file will later be copied.

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

2. Copy MSI File

The MSI file is copied from the control node to the Windows machine at C:\temp.

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

3. Install MSI Package

Ansible installs the MSI package on the Windows machine.

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

4. Create Configuration Directory

If the directory for the NXLog configuration file doesn't exist yet, it will be created.

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

5. Copy Configuration File

The nxlog.conf file is copied from the control node to the Windows machine.

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

6. Restart NXLog Service

Finally, the NXLog service is restarted so that the new configuration becomes active.

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

Running the Playbook

Save the playbook as, for example, install_nxlog.yml and run it with the following command:

ansible-playbook -i <your_inventory> install_nxlog.yml

Make sure your inventory properly contains the Windows host and that the connection via WinRM works.


With this playbook, you can quickly and cleanly install and configure NXLog on Windows. Good luck with your automation!