Add logic for building local ansible 'virtualenv'

Add makefile and targets for building local dev environment
Add script for linking dev collections into local collection dir
Add local collection dir to gitignore
This commit is contained in:
Ethan Paul 2021-12-20 18:35:15 -05:00
parent ed2fd510a5
commit fe0fc835cd
No known key found for this signature in database
GPG Key ID: 6A337337DF6B5B1A
3 changed files with 27 additions and 0 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ playbooks/testing.yml
*.idea
**/__pycache__/
.venv/
.ansible/

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
clean:
rm --recursive --force .ansible/
dev:
poetry install --remove-untracked
poetry run pre-commit install
poetry run ansible-galaxy collection install --requirements-file ./requirements.yaml --collections-path ./.ansible
./dynamically-link-local-collections.bash

View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
PWD=$(pwd)
ANSIBLE_NAMESPACE="skylab"
ANSIBLE_COLLECTION_DIR="$PWD/.ansible/ansible_collections"
mkdir --parents "$ANSIBLE_COLLECTION_DIR/$ANSIBLE_NAMESPACE"
for collection_path in "$PWD"/"$ANSIBLE_NAMESPACE"/*; do
collection=$(basename "$collection_path")
if [[ ! -L "$ANSIBLE_COLLECTION_DIR/$ANSIBLE_NAMESPACE/$collection" ]]; then
echo "Linking $ANSIBLE_NAMESPACE.$collection into $ANSIBLE_COLLECTION_DIR"
rm --recursive --force "${ANSIBLE_COLLECTION_DIR:?}/$ANSIBLE_NAMESPACE/$collection"
ln --symbolic "$PWD/$ANSIBLE_NAMESPACE/$collection" "$ANSIBLE_COLLECTION_DIR/$ANSIBLE_NAMESPACE/$collection"
fi
done
echo "Done!"