forked from davestephens/ansible-nas
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from anarion80/add_devenv
Add devenv
- Loading branch information
Showing
4 changed files
with
207 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,3 @@ | ||
source_url "https://raw.githubusercontent.com/cachix/devenv/82c0147677e510b247d8b9165c54f73d32dfd899/direnvrc" "sha256-7u4iDd1nZpxL4tCzmPG0dQgC5V+/44Ba+tHkPob1v2k=" | ||
|
||
use devenv |
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 |
---|---|---|
|
@@ -25,3 +25,12 @@ Session.vim | |
|
||
*.lock | ||
|
||
# Devenv | ||
.devenv* | ||
devenv.local.nix | ||
|
||
# direnv | ||
.direnv | ||
|
||
# pre-commit | ||
.pre-commit-config.yaml |
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,186 @@ | ||
{ | ||
pkgs, | ||
lib, | ||
config, | ||
... | ||
}: { | ||
name = "ansible-nas"; | ||
|
||
# https://devenv.sh/basics/ | ||
env = { | ||
GREET = "ansible-nas devenv"; | ||
}; | ||
|
||
# https://devenv.sh/packages/ | ||
packages = [ | ||
pkgs.git | ||
]; | ||
|
||
# https://devenv.sh/languages/ | ||
languages = { | ||
python = { | ||
enable = true; | ||
version = "3.12"; | ||
uv.enable = true; | ||
venv.enable = true; | ||
venv.requirements = '' | ||
pre-commit>=4.0.1 | ||
molecule>=24.9.0 | ||
pytest>=8.3.4 | ||
pytest-molecule>=2.0.0 | ||
molecule-plugins[docker]>=23.5.3 | ||
yamllint>=1.35.1 | ||
ansible-lint>=24.10.0 | ||
pymarkdownlnt>=0.9.25 | ||
ansible>=11.1.0 | ||
jmespath>=1.0.1 | ||
''; | ||
}; | ||
ansible = { | ||
enable = true; | ||
}; | ||
}; | ||
|
||
enterShell = '' | ||
echo Entering development environment for ansible-nas... | ||
echo | ||
echo 🦾 Available scripts: | ||
echo 🦾 | ||
${pkgs.gnused}/bin/sed -e 's| |••|g' -e 's|=| |' <<EOF | ${pkgs.util-linuxMinimal}/bin/column -t | ${pkgs.gnused}/bin/sed -e 's|^|🦾 |' -e 's|••| |g' | ||
${lib.generators.toKeyValue {} (lib.mapAttrs (name: value: value.description) config.scripts)} | ||
EOF | ||
echo | ||
''; | ||
|
||
scripts.run = { | ||
exec = '' | ||
# Initialize variables | ||
tag="" | ||
host="" | ||
# Function to display usage | ||
usage() { | ||
echo "Usage: $0 [-t|--tag <tag>] [-h|--host <host>]" | ||
echo "Options:" | ||
echo " -t, --tag Specify the Ansible tag" | ||
echo " -H, --host Specify the target host" | ||
echo " -h, --help Show this help message" | ||
exit 1 | ||
} | ||
# Parse named arguments | ||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
-t|--tag) tag="$2"; shift ;; | ||
-H|--host) host="$2"; shift ;; | ||
-h|--help) usage ;; | ||
*) echo "Unknown parameter: $1"; usage ;; | ||
esac | ||
shift | ||
done | ||
# Base command | ||
cmd="ansible-playbook -i inventories/my-ansible-nas/inventory nas.yml -b -K" | ||
# Echo the run message | ||
echo '🏃 Run Playbook' | ||
# Add tag if provided | ||
if [ ! -z "$tag" ]; then | ||
cmd="$cmd -t $tag" | ||
fi | ||
# Add host limit if provided | ||
if [ ! -z "$host" ]; then | ||
cmd="$cmd --limit $host" | ||
fi | ||
# Print the command being executed (optional, for debugging) | ||
echo "Executing: $cmd" | ||
# Execute the command | ||
eval $cmd | ||
''; | ||
description = "Run Playbook (add '-t tag' to only run certain role, and '-H host' to limit the playbook run to only that host from your inventory"; | ||
}; | ||
|
||
scripts.check = { | ||
exec = '' | ||
echo '🏃 Run Playbook Syntax Check' | ||
ansible-playbook -i inventory nas.yml --syntax-check | ||
''; | ||
description = "Run Playbook Syntax Check"; | ||
}; | ||
|
||
scripts.precommit = { | ||
exec = '' | ||
echo '🏃 Run pre-commit checks' | ||
pre-commit run --all-files | ||
''; | ||
description = "Run pre-commit checks"; | ||
}; | ||
|
||
scripts.pytest = { | ||
exec = '' | ||
echo '🏃 Run pytest' | ||
pytest --molecule-base-config=../../tests/molecule/base.yml | ||
''; | ||
description = "Run pytest"; | ||
}; | ||
|
||
scripts.roletest = { | ||
exec = '' | ||
# Initialize variables | ||
role="" | ||
# Function to display usage | ||
usage() { | ||
echo "Usage: $0 [-r|--role <role>]" | ||
echo "Options:" | ||
echo " -r, --role Specify the role to test (required)" | ||
echo " -h, --help Show this help message" | ||
exit 1 | ||
} | ||
# Parse named arguments | ||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
-r|--role) role="$2"; shift ;; | ||
-h|--help) usage ;; | ||
*) echo "Unknown parameter: $1"; usage ;; | ||
esac | ||
shift | ||
done | ||
# Check if tag is provided | ||
if [ -z "$role" ]; then | ||
echo "Error: Role parameter is required" | ||
usage | ||
fi | ||
# Base command | ||
cmd="molecule -c ../../tests/molecule/base.yml test" | ||
# Echo the run message | ||
echo '🏃 Running Molecule Tests' | ||
# Add role if provided | ||
if [ ! -z "$role" ]; then | ||
cd roles/$role | ||
fi | ||
# Print the command being executed (optional, for debugging) | ||
echo "Executing: $cmd" | ||
# Execute the command | ||
eval $cmd | ||
# Go back to root | ||
if [ ! -z "$role" ]; then | ||
cd ../../ | ||
fi | ||
''; | ||
description = "Run molecule role test (provide '-r role')"; | ||
}; | ||
} |
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,9 @@ | ||
--- | ||
inputs: | ||
nixpkgs: | ||
url: github:cachix/devenv-nixpkgs/rolling | ||
nixpkgs-python: | ||
url: github:cachix/nixpkgs-python | ||
inputs: | ||
nixpkgs: | ||
follows: nixpkgs |