]> arthur.barton.de Git - ansible-collection-boilerplate.git/blob - Makefile.boilerplate
Initial commit
[ansible-collection-boilerplate.git] / Makefile.boilerplate
1 #
2 # Ansible Boilerplate Collection: Makefile for inclusion into projects using it.
3 #
4
5 PYTHON ?= python3
6 SOURCE_ROOT ?= $(CURDIR)
7 VENV_D = $(SOURCE_ROOT)/.venv
8 VENV_BIN = $(VENV_D)/bin
9
10 this_makefile_path:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
11 this_dir:=$(shell cd $(dir $(this_makefile_path));pwd)
12
13 check-ansible: $(VENV_BIN)/ansible-lint
14 #       Check Ansible executable ...
15         "$(VENV_BIN)"/ansible --version
16 #       Check YAML files ...
17         "$(VENV_BIN)"/yamllint .
18 #       Run ansible-playbook syntax check, when a "site play" is found ...
19 ifneq ("$(wildcard playbooks/site.yml)","")
20         "$(VENV_BIN)"/ansible-playbook --syntax-check playbooks/site.yml
21 endif
22 ifneq ("$(wildcard site.yml)","")
23         "$(VENV_BIN)"/ansible-playbook --syntax-check site.yml
24 endif
25 #       Run ansible-lint ...
26         "$(VENV_BIN)"/ansible-lint --offline --project-dir "$(SOURCE_ROOT)" --show-relpath
27
28 distclean-ansible:
29 #       Remove Python "virtual environment" ...
30         rm -fr "$(SOURCE_ROOT)"/.venv
31 #       Remove Ansible Galaxy collections and roles
32         rm -fr "$(SOURCE_ROOT)"/ansible_galaxy/ansible_collections "$(SOURCE_ROOT)"/ansible_galaxy/ansible_roles
33 #       Remove cache directory, used by the Ansible "facts cache" for example ...
34         rm -fr "$(SOURCE_ROOT)"/.cache
35 #       Clean up symlinked commands in dependant projects ...
36         for cmd in "$(SOURCE_ROOT)"/bin/a "$(SOURCE_ROOT)"/bin/ap "$(SOURCE_ROOT)"/bin/aps; do \
37           test -h "$$cmd" && rm -f "$$cmd" || true; \
38          done
39
40 $(VENV_BIN)/ansible $(VENV_BIN)/ansible-galaxy $(VENV_BIN)/ansible-lint venv: $(VENV_BIN)/pip
41 #       Install/upgrade Python package manager
42         "$(VENV_BIN)"/pip install --upgrade pip wheel
43         touch "$(VENV_BIN)/pip" "$(VENV_BIN)/wheel"
44 #       Install/upgrade Python dependencies ...
45         "$(VENV_BIN)"/pip install --upgrade --requirement $(this_dir)/requirements.txt
46         touch "$(VENV_BIN)/ansible" "$(VENV_BIN)/ansible-galaxy" "$(VENV_BIN)/ansible-lint"
47
48 $(VENV_BIN)/pip:
49 #       Create/upgrade Python "virtual environment"
50         "$(PYTHON)" -m venv "$(SOURCE_ROOT)"/.venv
51
52 .PHONY: venv
53
54 ifneq ($(patsubst %..,,$(lastword $(SOURCE_ROOT))),)
55 # SOURCE_ROOT does not end in "..", so looks like this Makefile fragment is
56 # included in the top-level Makefile. So add some proprietary targets to the
57 # "common" toplevel targets:
58
59 all: $(VENV_BIN)/ansible $(VENV_BIN)/ansible-galaxy $(VENV_BIN)/ansible-lint
60 check: check-ansible
61 distclean: distclean-ansible
62
63 upgrade: $(SOURCE_ROOT)/bin/ansible-boilerplate
64         $(SOURCE_ROOT)/bin/ansible-boilerplate upgrade
65
66 .PHONY: check distclean
67 endif