diff --git a/.continue/rules/main.md b/.continue/rules/main.md new file mode 100644 index 0000000..bf50ba5 --- /dev/null +++ b/.continue/rules/main.md @@ -0,0 +1,13 @@ +# Project Architecture + +This is a ansible project for a small network of hosts: + +- Roles in `/roles` +- Inventory in `/inventory` +- Host definition in `site.xml` + +## Coding Standards + +- There are some scripts/files in other languages like python +- The project is managed in git. +- Follow the existing naming conventions: All ansible yaml files should have the ending .yaml \ No newline at end of file diff --git a/roles/backup_server/files/backup-disk-onoff.py b/roles/backup_server/files/backup-disk-onoff.py new file mode 100644 index 0000000..321c2f9 --- /dev/null +++ b/roles/backup_server/files/backup-disk-onoff.py @@ -0,0 +1,38 @@ +import subprocess +import json + +# Run the systemctl command and capture the output +try: + result = subprocess.run( + ["systemctl", "list-units", "--type=automount", "--no-legend", "--output=json"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + check=True + ) +except subprocess.CalledProcessError as e: + print(f"Error executing command: {e.stderr}") + exit(1) + +# Parse the JSON output +try: + units = json.loads(result.stdout) +except json.JSONDecodeError as e: + print(f"Error parsing JSON: {e}") + exit(1) + +# Filter units that are loaded, active, and sub: running +running_units = [] +for unit in units: + if ( + unit.get("load") == "loaded" and + unit.get("active") == "active" and + unit.get("sub") == "running" and + unit.get("unit", "").startswith("backup-") + ): + running_units.append(unit) + +# Output the results +print("Units with load: loaded, active: active, sub: running:") +for unit in running_units: + print(f" - {unit['unit']}: {unit['description']}")