diff --git a/README.md b/README.md index 0331185..d73691c 100644 --- a/README.md +++ b/README.md @@ -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.
The command field actually gets executed on the end-point.
+### 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: + +MeshCentral Operating System Version
+MeshBook yaml example + +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/)): diff --git a/assets/meshbook_yaml_os.png b/assets/meshbook_yaml_os.png new file mode 100644 index 0000000..fb445cb Binary files /dev/null and b/assets/meshbook_yaml_os.png differ diff --git a/assets/meshcentral_os.png b/assets/meshcentral_os.png new file mode 100644 index 0000000..5e419f2 Binary files /dev/null and b/assets/meshcentral_os.png differ diff --git a/examples/echo_example.yaml b/examples/echo_example.yaml index a64d151..6900e37 100644 --- a/examples/echo_example.yaml +++ b/examples/echo_example.yaml @@ -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" diff --git a/meshbook.py b/meshbook.py index 153ffaf..ef06352 100644 --- a/meshbook.py +++ b/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: