-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.boilerplate
69 lines (58 loc) · 2.59 KB
/
Makefile.boilerplate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
# Ansible Boilerplate Collection: Makefile for inclusion into projects using it.
#
PYTHON ?= python3
SOURCE_ROOT ?= $(CURDIR)
VENV_D = $(SOURCE_ROOT)/.venv
VENV_BIN = $(VENV_D)/bin
check-ansible: $(VENV_BIN)/ansible-lint
# Check Ansible executable ...
"$(VENV_BIN)"/ansible --version
# Run ansible-playbook syntax check, when a "site play" is found ...
ifneq ("$(wildcard playbooks/site.yml)","")
"$(VENV_BIN)"/ansible-playbook --syntax-check playbooks/site.yml
endif
ifneq ("$(wildcard site.yml)","")
"$(VENV_BIN)"/ansible-playbook --syntax-check site.yml
endif
# Run ansible-lint ...
"$(VENV_BIN)"/ansible-lint --offline --project-dir "$(SOURCE_ROOT)" --show-relpath
distclean-ansible:
# Remove Python "virtual environment" ...
rm -fr "$(SOURCE_ROOT)"/.venv
# Remove Ansible Galaxy collections and roles
rm -fr "$(SOURCE_ROOT)"/ansible_galaxy/ansible_collections "$(SOURCE_ROOT)"/ansible_galaxy/ansible_roles
# Try to remove the "ansible_galaxy" directory (if empty), but ignore errors.
rmdir "$(SOURCE_ROOT)"/ansible_galaxy || true
# Remove cache directory, used by the Ansible "facts cache" for example ...
rm -fr "$(SOURCE_ROOT)"/.cache
# Clean up symlinked commands in dependant projects ...
for cmd in "$(SOURCE_ROOT)"/bin/a "$(SOURCE_ROOT)"/bin/ap "$(SOURCE_ROOT)"/bin/aps; do \
test -h "$$cmd" && rm -f "$$cmd" || true; \
done
$(VENV_BIN)/ansible $(VENV_BIN)/ansible-galaxy $(VENV_BIN)/ansible-lint venv: $(SOURCE_ROOT)/requirements.txt $(VENV_BIN)/pip
# Install/upgrade Python package manager
"$(VENV_BIN)"/pip install --upgrade pip wheel
# Install/upgrade Python dependencies ...
"$(VENV_BIN)"/pip install --upgrade --requirement $(SOURCE_ROOT)/requirements.txt
touch -c "$(VENV_BIN)/ansible" "$(VENV_BIN)/ansible-galaxy" "$(VENV_BIN)/ansible-lint"
$(VENV_BIN)/pip:
# Create/upgrade Python "virtual environment"
"$(PYTHON)" -m venv "$(SOURCE_ROOT)"/.venv
touch -c "$(VENV_BIN)/pip"
.PHONY: venv
ifneq ($(patsubst %..,,$(lastword $(SOURCE_ROOT))),)
# SOURCE_ROOT does not end in "..", so looks like this Makefile fragment is
# included in the top-level Makefile. So add some proprietary targets to the
# "common" toplevel targets:
all: $(VENV_BIN)/ansible $(VENV_BIN)/ansible-galaxy $(VENV_BIN)/ansible-lint
check: check-ansible
distclean: distclean-ansible
# Upgrade the project using "ansible-boilerplate upgrade" command:
upgrade: $(SOURCE_ROOT)/bin/ansible-boilerplate
$(SOURCE_ROOT)/bin/ansible-boilerplate upgrade
# Clean up, for example after upgrading the project.
cleanup:
find $(SOURCE_ROOT) \( -name '*.old' -o -name '*.new' \) -exec rm -iv {} \;
.PHONY: all check distclean upgrade cleanup
endif