mirror of
https://github.com/DaanSelen/meshbook.git
synced 2026-02-20 16:32:11 +00:00
Added basic operating system filtering.
This commit is contained in:
@@ -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/)):
|
||||
|
||||
BIN
assets/meshbook_yaml_os.png
Normal file
BIN
assets/meshbook_yaml_os.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/meshcentral_os.png
Normal file
BIN
assets/meshcentral_os.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
@@ -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"
|
||||
|
||||
11
meshbook.py
11
meshbook.py
@@ -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"]
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user