]> arthur.barton.de Git - ansible-collection-boilerplate.git/blob - Makefile.boilerplate
ansible.cfg: "collections_paths" is deprecated, use singular
[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 check-ansible: $(VENV_BIN)/ansible-lint
11 #       Check Ansible executable ...
12         "$(VENV_BIN)"/ansible --version
13 #       Run ansible-playbook syntax check, when a "site play" is found ...
14 ifneq ("$(wildcard playbooks/site.yml)","")
15         "$(VENV_BIN)"/ansible-playbook --syntax-check playbooks/site.yml
16 endif
17 ifneq ("$(wildcard site.yml)","")
18         "$(VENV_BIN)"/ansible-playbook --syntax-check site.yml
19 endif
20 #       Run ansible-lint ...
21         "$(VENV_BIN)"/ansible-lint --offline --project-dir "$(SOURCE_ROOT)" --show-relpath
22
23 distclean-ansible:
24 #       Remove Python "virtual environment" ...
25         rm -fr "$(SOURCE_ROOT)"/.venv
26 #       Remove Ansible Galaxy collections and roles
27         rm -fr "$(SOURCE_ROOT)"/ansible_galaxy/ansible_collections "$(SOURCE_ROOT)"/ansible_galaxy/ansible_roles
28 #       Try to remove the "ansible_galaxy" directory (if empty), but ignore errors.
29         rmdir "$(SOURCE_ROOT)"/ansible_galaxy || true
30 #       Remove cache directory, used by the Ansible "facts cache" for example ...
31         rm -fr "$(SOURCE_ROOT)"/.cache
32 #       Clean up symlinked commands in dependant projects ...
33         for cmd in "$(SOURCE_ROOT)"/bin/a "$(SOURCE_ROOT)"/bin/ap "$(SOURCE_ROOT)"/bin/aps; do \
34           test -h "$$cmd" && rm -f "$$cmd" || true; \
35          done
36
37 $(VENV_BIN)/ansible $(VENV_BIN)/ansible-galaxy $(VENV_BIN)/ansible-lint venv: $(SOURCE_ROOT)/requirements.txt $(VENV_BIN)/pip
38 #       Install/upgrade Python package manager
39         "$(VENV_BIN)"/pip install --upgrade pip wheel
40 #       Install/upgrade Python dependencies ...
41         "$(VENV_BIN)"/pip install --upgrade --requirement $(SOURCE_ROOT)/requirements.txt
42         touch -c "$(VENV_BIN)/ansible" "$(VENV_BIN)/ansible-galaxy" "$(VENV_BIN)/ansible-lint"
43
44 $(VENV_BIN)/pip:
45 #       Create/upgrade Python "virtual environment"
46         "$(PYTHON)" -m venv "$(SOURCE_ROOT)"/.venv
47         touch -c "$(VENV_BIN)/pip"
48
49 .PHONY: venv
50
51 ifneq ($(patsubst %..,,$(lastword $(SOURCE_ROOT))),)
52 # SOURCE_ROOT does not end in "..", so looks like this Makefile fragment is
53 # included in the top-level Makefile. So add some proprietary targets to the
54 # "common" toplevel targets:
55
56 all: $(VENV_BIN)/ansible $(VENV_BIN)/ansible-galaxy $(VENV_BIN)/ansible-lint
57 check: check-ansible
58 distclean: distclean-ansible
59
60 upgrade: $(SOURCE_ROOT)/bin/ansible-boilerplate
61         $(SOURCE_ROOT)/bin/ansible-boilerplate upgrade
62
63 .PHONY: check distclean
64 endif