Last active
July 3, 2020 08:07
-
-
Save ixs/1a479bcc3bd4b9ffc28e9ed2e6bba1f2 to your computer and use it in GitHub Desktop.
Makefile to drive ansible from a venv
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
# Makefile | |
SHELL = /bin/bash | |
PYTHON_EXE = python3 | |
TOPDIR = $(shell git rev-parse --show-toplevel) | |
all: venv ## Build complete environment | |
help: # Display help | |
@awk -F ':|##' \ | |
'/^[^\t].+?:.*?##/ {\ | |
printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \ | |
}' $(MAKEFILE_LIST) | |
venv: venv/bin/activate ## Build virtual environment | |
venv/bin/activate: requirements.txt | |
if [ ! -d venv ]; then \ | |
virtualenv -p $(PYTHON_EXE) venv; \ | |
if type rpm >& /dev/null; then \ | |
if rpm -q libselinux-python; then \ | |
. venv/bin/activate; \ | |
cp -fR $$(rpm -ql libselinux-python) "$$VIRTUAL_ENV"/lib/python3.8/site-packages; \ | |
else \ | |
echo "No SELinux Python libraries available, skipping installation"; \ | |
fi \ | |
fi \ | |
fi | |
. venv/bin/activate; pip install -U pip; pip install -r requirements.txt | |
clean: ## Delete all generated artefacts | |
$(RM) -rf venv | |
find . -name "*.pyc" -exec $(RM) -rf {} \; | |
check: check-ansible-lint ## Run linters | |
check-ansible-lint: venv ## Run ansible linter | |
. venv/bin/activate; tools/ansible-lint.sh | |
sync: ## Synchronize ansible data | |
git pull --rebase | |
.PHONY:clean sync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment