-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
53 lines (43 loc) · 1.3 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
CONTAINER = docker container run \
--rm --interactive --tty \
--volume $(CURDIR):/data:ro \
--workdir /data \
--volume $(HOME)/.ssh:/root/.ssh:ro \
--volume $(realpath $(HOME)/.ssh/config):/root/.ssh/config:ro \
--volume /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock:ro \
--env SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock \
ansible
ifndef host
host = $(error Missing value for variable `host')
endif
tags ?= all
.SILENT:
run: secrets image lint
$(CONTAINER) ansible-playbook main.yml \
--limit $(host) \
--tags $(tags)
debug: image
$(CONTAINER) ansible $(host) \
--module-name ansible.builtin.setup
$(CONTAINER) ansible $(host) \
--module-name ansible.builtin.debug \
--args var=hostvars[inventory_hostname]
shell: image
$(CONTAINER) bash
clean:
! docker image inspect ansible >/dev/null 2>&1 || \
docker image rm ansible
lint: image
$(CONTAINER) ansible-lint -qq --strict --offline
secrets:
for secret in $$(grep -Eor '^(.+):.+secret_\1' *_vars | cut -d: -f1,2); do \
file="$${secret%%.*}_secrets.yml"; \
var="secret_$${secret##*:}"; \
grep -sq "^$$var: " "$$file" && continue; \
printf "$$secret: "; \
read -r value; \
echo "$$var: $$value" >> "$$file"; \
done
image:
docker image inspect ansible >/dev/null 2>&1 || \
docker image build --tag ansible .