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 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>
|
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:
|
# Example:
|
||||||
|
|
||||||
For the example, I used the following yaml file (you can find more in [this directory](./examples/)):
|
For the example, I used the following yaml file (you can find more in [this directory](./examples/)):
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
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.
|
name: Echo a string to the terminal through the meshbook example.
|
||||||
group: "Dev"
|
group: "Dev"
|
||||||
|
target_os: Debian GnU/Linux 12 (bookworm)
|
||||||
variables:
|
variables:
|
||||||
- name: file
|
- name: file
|
||||||
value: "/etc/os-release"
|
value: "/etc/os-release"
|
||||||
|
|||||||
+9
-2
@@ -103,7 +103,10 @@ async def gather_targets(playbook: dict, group_list: dict) -> dict:
|
|||||||
for group in group_list:
|
for group in group_list:
|
||||||
for device in group_list[group]:
|
for device in group_list[group]:
|
||||||
if device["reachable"] and pseudo_target == device["device_name"]:
|
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:
|
elif "group" in playbook and "device" not in playbook:
|
||||||
pseudo_target = playbook["group"]
|
pseudo_target = playbook["group"]
|
||||||
@@ -112,8 +115,12 @@ async def gather_targets(playbook: dict, group_list: dict) -> dict:
|
|||||||
if pseudo_target == group:
|
if pseudo_target == group:
|
||||||
for device in group_list[group]:
|
for device in group_list[group]:
|
||||||
if device["reachable"]:
|
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
|
return target_list
|
||||||
|
|
||||||
async def execute_playbook(session: meshctrl.Session, targets: dict, playbook: dict, group_list: dict) -> None:
|
async def execute_playbook(session: meshctrl.Session, targets: dict, playbook: dict, group_list: dict) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user