Skip to content

Commit

Permalink
Added basic operating system filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanSelen committed Jan 31, 2025
1 parent 0cd653d commit 7dd3290
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ The tasks you want to run should be contained under the `tasks:` with two fields
The name field is for the user of meshbook, to clarify what the following command does in a summary.<br>
The command field actually gets executed on the end-point.<br>

### Granual Operating System control:

I have made the program so it can have a basic filter with the Operating systems. If you have a mixed group, then you need to match the image below like this:

<img src="./assets/meshcentral_os.png" alt="MeshCentral Operating System Version" width="600"/><br>
<img src="./assets/meshbook_yaml_os.png" alt="MeshBook yaml example" width="600"/>

This will filter the nodes/machines in the MeshCentral group to the ones matching this. Very basic and open for feedback. This must match the full string, not case sensitive.

# Example:

For the example, I used the following yaml file (you can find more in [this directory](./examples/)):
Expand Down
Binary file added assets/meshbook_yaml_os.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/meshcentral_os.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/echo_example.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Echo a string to the terminal through the meshbook example.
group: "Dev"
target_os: Debian GnU/Linux 12 (bookworm)
variables:
- name: file
value: "/etc/os-release"
Expand Down
11 changes: 9 additions & 2 deletions meshbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ async def gather_targets(playbook: dict, group_list: dict) -> dict:
for group in group_list:
for device in group_list[group]:
if device["reachable"] and pseudo_target == device["device_name"]:
target_list.append(device["device_id"])
if "target_os" in playbook and str(playbook["target_os"]).lower() == str(device["device_os"]).lower():
target_list.append(device["device_id"])
elif "target_os" not in playbook:
target_list.append(device["device_id"])

elif "group" in playbook and "device" not in playbook:
pseudo_target = playbook["group"]
Expand All @@ -112,8 +115,12 @@ async def gather_targets(playbook: dict, group_list: dict) -> dict:
if pseudo_target == group:
for device in group_list[group]:
if device["reachable"]:
target_list.append(device["device_id"])
if "target_os" in playbook and str(playbook["target_os"]).lower() == str(device["device_os"]).lower():
target_list.append(device["device_id"])
elif "target_os" not in playbook:
target_list.append(device["device_id"])

print(target_list)
return target_list

async def execute_playbook(session: meshctrl.Session, targets: dict, playbook: dict, group_list: dict) -> None:
Expand Down

0 comments on commit 7dd3290

Please sign in to comment.