Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit 2f849cf

Browse files
committed
generalize ansible recipes in makefile
1 parent 8831d1d commit 2f849cf

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

env/make/ansible.mk

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
_playbook = ansible-playbook -i env/ansible/.private.hosts
2-
_recipes = env/ansible/ubuntu.yml env/ansible/docker.yml env/ansible/service.yml
2+
_recipes = ubuntu docker service
33

44
.PHONY: ansible-playbook-apply
5+
ansible-playbook-apply: recipes=$(foreach recipe,$(_recipes),env/ansible/$(recipe).yml)
56
ansible-playbook-apply:
6-
@$(_playbook) $(_recipes)
7+
$(_playbook) $(recipes)
78

89
.PHONY: ansible-playbook-check
10+
ansible-playbook-check: recipes=$(foreach recipe,$(_recipes),env/ansible/$(recipe).yml)
911
ansible-playbook-check:
10-
@$(_playbook) --check $(_recipes)
12+
$(_playbook) --check $(recipes)
1113

1214
.PHONY: ansible-playbook-diff
15+
ansible-playbook-diff: recipes=$(foreach recipe,$(_recipes),env/ansible/$(recipe).yml)
1316
ansible-playbook-diff:
14-
@$(_playbook) --diff $(_recipes)
17+
$(_playbook) --diff $(recipes)
1518

1619

17-
.PHONY: ansible-playbook-for-ubuntu
18-
ansible-playbook-for-ubuntu:
19-
$(eval _recipes = env/ansible/ubuntu.yml)
20-
@echo recipe $(_recipes) will be used
20+
define recipe_tpl
2121

22-
.PHONY: ansible-playbook-for-docker
23-
ansible-playbook-for-docker:
24-
$(eval _recipes = env/ansible/docker.yml)
25-
@echo recipe $(_recipes) will be used
22+
.PHONY: ansible-playbook-for-$(1)
23+
ansible-playbook-for-$(1):
24+
$$(eval _recipes = $(1))
25+
@echo recipe env/ansible/$$(_recipes).yml will be used
2626

27-
.PHONY: ansible-playbook-for-service
28-
ansible-playbook-for-service:
29-
$(eval _recipes = env/ansible/service.yml)
30-
@echo recipe $(_recipes) will be used
27+
endef
28+
29+
render_recipe_tpl = $(eval $(call recipe_tpl,$(recipe)))
30+
$(foreach recipe,$(_recipes),$(render_recipe_tpl))

0 commit comments

Comments
 (0)