add bare ansible config
This commit is contained in:
46
ansible/Makefile
Normal file
46
ansible/Makefile
Normal file
@@ -0,0 +1,46 @@
|
||||
hosts = $(wildcard host_vars/*.yml)
|
||||
|
||||
logs = $(patsubst host_vars/%.yml, logs/%.json, $(hosts) )
|
||||
|
||||
playbooks = $(wildcard playbooks/*.yml)
|
||||
plays = $(patsubst playbooks/%.yml, %, $(playbooks) )
|
||||
|
||||
defaults += $(wildcard logs/*)
|
||||
|
||||
###### Recipes ######
|
||||
|
||||
.PHONY: help
|
||||
help: ## Print the help message.
|
||||
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z._-]+:.*?## / {printf "\033[36m%s\033[0m : %s\n", $$1, $$2}' $(MAKEFILE_LIST) | \
|
||||
column -s ':' -t
|
||||
|
||||
.PHONY: lint
|
||||
lint: $(playbooks) | .ansible/ ## Check syntax and lint all playbooks
|
||||
ansible-playbook --syntax-check $^
|
||||
ansible-lint $^
|
||||
|
||||
.PHONY: records
|
||||
records: $(logs) ## Current info on each host
|
||||
|
||||
$(logs): logs/%.json: | logs/
|
||||
ansible -m setup $(basename $(@F) ) > $@
|
||||
|
||||
-include logs/play.mk
|
||||
|
||||
make_play = printf '.PHONY: %s\n%s: %s \#\# %s\n\n' '$(notdir $(basename $1) )' '$(notdir $(basename $1) )' '$1' '$(shell grep -m1 -oP 'name: \K.*' $1)'
|
||||
|
||||
logs/play.mk: playbooks/*.yml
|
||||
@$(RM) $@
|
||||
@$(foreach book, $^, \
|
||||
$(call make_play, $(book), $@ ) >> $@ ; \
|
||||
printf '\t%s\n\n' 'ansible-playbook $(book)' >> $@ ; \
|
||||
)
|
||||
|
||||
%/:
|
||||
mkdir $@
|
||||
echo '*' > $@.gitignore
|
||||
|
||||
.PHONY: clean
|
||||
clean: ## Remove generated files.
|
||||
$(RM) $(defaults)
|
||||
|
||||
Reference in New Issue
Block a user