57 lines
1.6 KiB
Makefile
57 lines
1.6 KiB
Makefile
SHELL := /bin/bash
|
|
|
|
INVENTORY ?= inventory.ini
|
|
PLAYBOOK ?= site.yml
|
|
EXTRA_VARS ?=
|
|
ANSIBLE ?= ansible-playbook
|
|
|
|
.PHONY: help ping check run dry-run diff vars tree clean
|
|
|
|
help:
|
|
@echo "Targets:"
|
|
@echo " make ping - ping hosts (Ansible)"
|
|
@echo " make check - syntax-check playbook"
|
|
@echo " make run - apply playbook"
|
|
@echo " make dry-run - check mode with diff (no changes)"
|
|
@echo " make diff - show diff of changes (implies --check)"
|
|
@echo " make vars - show vars for a host (requires host=...)"
|
|
@echo " make tree - show repository tree"
|
|
@echo ""
|
|
@echo "Examples:"
|
|
@echo " make run EXTRA_VARS='-e ssh_allow_cidrs_v4=[\"1.2.3.4/32\"]'"
|
|
@echo " make vars host=bbb"
|
|
|
|
ping:
|
|
ansible -i $(INVENTORY) vps -m ping
|
|
|
|
check:
|
|
$(ANSIBLE) -i $(INVENTORY) $(PLAYBOOK) --syntax-check
|
|
|
|
run:
|
|
$(ANSIBLE) -i $(INVENTORY) $(PLAYBOOK) --become $(EXTRA_VARS)
|
|
|
|
dry-run:
|
|
$(ANSIBLE) -i $(INVENTORY) $(PLAYBOOK) --become --check --diff $(EXTRA_VARS)
|
|
|
|
diff:
|
|
$(ANSIBLE) -i $(INVENTORY) $(PLAYBOOK) --become --check --diff $(EXTRA_VARS)
|
|
|
|
vars:
|
|
@if [[ -z "$(host)" ]]; then echo "ERROR: host is required, e.g. make vars host=bbb"; exit 2; fi
|
|
ansible -i $(INVENTORY) $(host) -m debug -a "var=hostvars[inventory_hostname]" | sed -n '1,200p'
|
|
|
|
tree:
|
|
@python3 - <<'PY'
|
|
import os
|
|
for root, dirs, files in os.walk('.'):
|
|
dirs[:] = [d for d in dirs if d not in {'.git','__pycache__','.venv','.cache'}]
|
|
level = root.count(os.sep)
|
|
indent = ' ' * level
|
|
print(f"{indent}{os.path.basename(root)}/")
|
|
subindent = ' ' * (level + 1)
|
|
for f in sorted(files):
|
|
print(f"{subindent}{f}")
|
|
PY
|
|
|
|
clean:
|
|
@find . -name "*.retry" -delete
|