-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.template
73 lines (50 loc) · 2.04 KB
/
Makefile.template
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# add the IP address, username and hostname of the target host here
IP=192.168.0.x
USERNAME=
HOSTNAME=
include ./*.mk
all:
@echo ""
@echo "Available targets:"
@echo ""
@echo "init: will install basic requirements (will ask several times for a password)"
@echo "install: will install the host with what is defined in install-host.yml"
@echo "update: run OS updates"
@echo "ssh: jump ssh to host"
@echo "role-update: update all downloades roles"
@echo "available-roles: list known roles which can be downloaded"
@echo "clean: delete all temporary files"
@echo ""
@echo ""
@echo " current used IP: ${IP}"
@echo " current used user: ${USERNAME}"
@echo "current used hostname: ${HOSTNAME}"
@echo ""
init: install-host.yml update-host.yml
@echo ""
@echo "will init host ${IP}, install ssh key and basic packages"
@echo ""
@echo "Note: NEVER use this step to init a host in an untrusted network!"
@echo "Note: this will OVERWRITE any existing keys on the host!"
@echo ""
@echo "5 seconds to abort ..."
@echo ""
@sleep 5
./init_host.sh "${IP}" "${USERNAME}"
install: role-update install-host.yml
ansible-playbook --ssh-common-args='-o UserKnownHostsFile=./known_hosts' -i ${IP}, -u ${USERNAME} install-host.yml --extra-vars "hostname=${HOSTNAME}"
update:
ansible-playbook --ssh-common-args='-o UserKnownHostsFile=./known_hosts' -i ${IP}, -u ${USERNAME} update-host.yml
# https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile
no_targets__:
role-update:
sh -c "$(MAKE) -p no_targets__ | awk -F':' '/^[a-zA-Z0-9][^\$$#\/\\t=]*:([^=]|$$)/ {split(\$$1,A,/ /);for(i in A)print A[i]}' | grep -v '__\$$' | grep '^ansible-update-*'" | xargs -n 1 make --no-print-directory
ssh:
ssh -o UserKnownHostsFile=./known_hosts ${USERNAME}@${IP}
install-host.yml:
cp -a install-host.template install-host.yml
update-host.yml:
cp -a update-host.template update-host.yml
clean:
rm -rf ./known_hosts install-host.yml update-host.yml
.PHONY: all init install update ssh common clean no_targets__ role-update