Skip to content

MeshCentral utility for programmatically sending out commands with YAML files! Using the libmeshctrl Python library.

License

Notifications You must be signed in to change notification settings

DaanSelen/meshbook

Repository files navigation

Meshbook

CodeQL Advanced

Note

πŸ’¬ If you experience issues or have suggestions, submit an issue β€” I'll respond ASAP!


Meshbook is a tool to programmatically manage MeshCentral-managed machines, inspired by tools like Ansible.

What problem does it solve?

Meshbook is designed to:

  • Automate system updates or commands across multiple systems via MeshCentral, even behind third-party-managed firewalls.
  • Allow configuration using simple and readable YAML files (like Ansible playbooks).
  • Simplify the use of group-based or tag-based device targeting.

🏁 Quick Start

βœ… Prerequisites

  • Python 3.7+

  • Git

  • Access to a MeshCentral instance and credentials with:

    • Remote Commands
    • Details
    • Agent Console permissions

A service account with access to the relevant device groups is recommended.


πŸ”§ Installation

Linux

git clone https://github.com/daanselen/meshbook
cd ./meshbook
python3 -m venv ./venv
source ./venv/bin/activate
pip install -r requirements.txt
cp ./templates/meshcentral.conf.template ./meshcentral.conf

Windows (PowerShell)

git clone https://github.com/daanselen/meshbook
cd .\meshbook
python -m venv .\venv
.\venv\Scripts\activate
pip install -r .\requirements.txt
cp .\templates\meshcentral.conf.template .\meshcentral.conf

πŸ“Œ Rename meshcentral.conf.template to meshcentral.conf and fill in your actual connection details. The URL must start with wss://<MeshCentral-Host>.


πŸš€ Running Meshbook

Once installed and configured, run a playbook like this:

Linux:

python3 meshbook.py -pb ./examples/echo_example.yaml

Windows:

.\venv\Scripts\python.exe .\meshbook.py -pb .\examples\echo_example.yaml

Use --help to explore available command-line options:

python3 meshbook.py --help

πŸ› οΈ Creating Configurations

Meshbook configurations are written in YAML. Below is an overview of supported fields.

▢️ Group Targeting (Primary*)

---
name: My Configuration
group: "Dev Machines"
powershell: true
variables:
  - name: message
    value: "Hello from Meshbook"
tasks:
  - name: Echo a message
    command: 'echo "{{ message }}"'
  • group: MeshCentral group (aka "mesh"). Quotation marks required for multi-word names.
  • powershell: Set true for PowerShell commands on Windows clients.

▢️ Device Targeting (Secondary*)

You can also target a specific device rather than a group. See apt_update_example.yaml for reference.

▢️ Variables

Variables are replaced by Meshbook before execution. Syntax:

variables:
  - name: example_var
    value: "Example value"

tasks:
  - name: Use the variable
    command: 'echo "{{ example_var }}"'
  • Primary and Secondary mark the order in which will take prescendence

▢️ Tasks

Define multiple tasks:

tasks:
  - name: Show OS info
    command: "cat /etc/os-release"

Each task must include:

  • name: Description for human readability.
  • command: The actual shell or PowerShell command.

πŸͺŸ Windows Client Notes

  • Keep your os_categories.json up to date for proper OS filtering.
  • Ensure Windows commands are compatible (use powershell: true if needed).
  • Examples are available in examples/windows.

πŸ”Ž OS & Tag Filtering

Filter by OS

You can limit commands to specific OS types:

target_os: "Linux"  # As defined in os_categories.json

See docs/operating_system_filtering.md for details.

Filter by Tag

You can also filter using MeshCentral tags:

target_tag: "Production"

⚠️ Tag values are case-sensitive.


πŸ“‹ Example Playbook

---
name: Echo OS Info
group: "Dev"
target_os: "Linux"
variables:
  - name: file
    value: "/etc/os-release"
tasks:
  - name: Show contents of os-release
    command: "echo $(cat {{ file }})"

Sample output:

{
  "Task 1": {
    "task_name": "Show contents of os-release",
    "data": [
      {
        "command": "echo $(cat /etc/os-release)",
        "result": [
          "NAME=\"Ubuntu\"",
          "VERSION=\"22.04.4 LTS (Jammy Jellyfish)\""
        ],
        "complete": true,
        "device_name": "dev-host1"
      }
    ]
  }
}

⚠️ Blocking Commands Warning

Avoid using commands that block indefinitely β€” MeshCentral requires non-blocking execution.

🚫 Examples of bad (blocking) commands:

apt upgrade       # Without -y
sleep infinity
ping 1.1.1.1      # Without -c

βœ… Use instead:

apt upgrade -y
ping 1.1.1.1 -c 1

πŸ§ͺ Check Python Environment

Sometimes the wrong Python interpreter or environment is used. To verify:

python3 -m pip list
pip3 list

The lists should match. If not, make sure the correct environment is activated.


πŸ“‚ Project Structure (excerpt)

meshbook/
β”œβ”€β”€ books/
β”‚   β”œβ”€β”€ apt-update.yaml
β”‚   └── rdp.yaml
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ linux/
β”‚   β”‚   β”œβ”€β”€ apt_update_example.yaml
β”‚   β”‚   └── ...
β”‚   └── windows/
β”‚       β”œβ”€β”€ get_sys_info.yaml
β”‚       └── ...
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ executor.py
β”‚   └── utilities.py
β”œβ”€β”€ meshbook.py
β”œβ”€β”€ os_categories.json
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ templates/
β”‚   └── config.conf.template

πŸ“„ License

This project is licensed under the terms of the GPL3 License. See LICENSE.

About

MeshCentral utility for programmatically sending out commands with YAML files! Using the libmeshctrl Python library.

Resources

License

Security policy

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages