-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workflows: check for missing mac_overrides
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
# Initialize a variable to track if any errors are found | ||
error_found=0 | ||
|
||
# Define patterns for location files and model files | ||
location_files='locations/*.yml' | ||
model_files='group_vars/model_*.yml' | ||
|
||
# Find all models that require a mac_override | ||
declare -A mac_override_required_models | ||
|
||
for model_file_path in $model_files; do | ||
# Extract model name from file path | ||
model_file=$(basename "$model_file_path" .yml) | ||
model_name=${model_file#model_} | ||
|
||
# Check if the model requires mac_override | ||
requires_mac_override=$(yq '.requires_mac_override' "$model_file_path" | tr -d '"') | ||
|
||
# Store the result in the associative array | ||
mac_override_required_models["$model_name"]=$requires_mac_override | ||
done | ||
|
||
# Find all missing mac_overrides | ||
for location_file in $location_files; do | ||
# Get hosts as a single YAML block to minimize calls to yq | ||
hosts=$(yq '.hosts' "$location_file") | ||
|
||
# Loop through each host entry | ||
for i in $(seq 0 $(($(echo "$hosts" | yq '. | length') - 1))); do | ||
hostname=$(echo "$hosts" | yq ".[$i].hostname" | tr -d '"') | ||
model=$(echo "$hosts" | yq ".[$i].model" | tr -d '"') | ||
mac_override=$(echo "$hosts" | yq ".[$i].mac_override" | tr -d '"') | ||
|
||
# Convert model name to match the model file format (underscore instead of hyphen) | ||
model_name=${model//-/_} | ||
|
||
# Check if the model requires mac_override using the associative array | ||
requires_mac_override=${mac_override_required_models["$model_name"]} | ||
|
||
if [ "$requires_mac_override" = "true" ]; then | ||
if [ "$mac_override" == "null" ]; then | ||
# Output the missing mac_override details immediately | ||
echo "Host $hostname (model: $model) in $location_file is missing mac_override." | ||
error_found=1 | ||
fi | ||
fi | ||
done | ||
done | ||
|
||
# Exit with a non-zero status code if any errors were found | ||
if [ "$error_found" -eq 1 ]; then | ||
exit 1 | ||
else | ||
echo "No MAC override issues found." | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: Check missing mac_overrides | ||
|
||
on: [push, pull_request] # yamllint disable-line rule:truthy | ||
|
||
jobs: | ||
check-mac-override-missing: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout branch | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Run mac_override missing check | ||
run: | | ||
./.github/checks/check-mac-override-missing.sh |