From fe0fc835cdb9619b2e1e1500e8e3e31defb30d45 Mon Sep 17 00:00:00 2001 From: Ethan Paul Date: Mon, 20 Dec 2021 18:35:15 -0500 Subject: [PATCH] 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 --- .gitignore | 1 + Makefile | 8 ++++++++ dynamically-link-local-collections.bash | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 Makefile create mode 100755 dynamically-link-local-collections.bash diff --git a/.gitignore b/.gitignore index 3efabe7..f56294b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ playbooks/testing.yml *.idea **/__pycache__/ .venv/ +.ansible/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d13d03d --- /dev/null +++ b/Makefile @@ -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 diff --git a/dynamically-link-local-collections.bash b/dynamically-link-local-collections.bash new file mode 100755 index 0000000..c6d8ee0 --- /dev/null +++ b/dynamically-link-local-collections.bash @@ -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!"