-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (64 loc) · 2.71 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Ansible makefile for doing stuff with things.
SHELL=/bin/bash
ANSBIN=/usr/bin/ansible-playbook
# Which roles and collections should be installed? Use dots for roles, slashes for collections
ANSROLES=gantsign.golang geerlingguy.php-versions jhu-sheridan-libraries.postfix-smarthost geerlingguy.nodejs
ANSCOLL=vyos/vyos community/general ansible/posix community/docker community/mysql
BINS=$(ANSBIN) /usr/bin/vim /usr/bin/ping /usr/bin/netstat /usr/bin/wget /usr/bin/unzip
PKGS=ansible vim iputils-ping net-tools wget unzip
ANSIBLE_HOST_KEY_CHECKING=False
export ANSIBLE_HOST_KEY_CHECKING
GITCONFIG=$(HOME)/.gitconfig
.PHONY: setup
setup: $(BINS) $(GITCONFIG) group_vars/all/cloudflare.yaml ansible-collections
$(BINS):
apt-get -y install $(PKGS)
.PHONY: me
me: setup /etc/ansible.hostname
@MYIPS=$$(ip -o addr | egrep -v '(\ lo|\ docker)' | awk '/inet / { print $$4 }' | cut -d/ -f1 | paste -sd ','); \
echo ansible-playbook main.yml -l $$MYIPS; \
ansible-playbook main.yml -l $$MYIPS
.PHONY: hostname
hostname: setup /etc/hosts
/etc/hosts: /etc/ansible.hostname
$(ANSBIN) localhost.yml -e hostname=$(shell cat /etc/ansible.hostname)
.PHONY: fhostname
fhostname /etc/ansible.hostname:
@C=$(shell hostname); echo "Current hostname '$$C'"; read -e -p "Set hostname (blank to not change): " h; \
if [ "$$h" ]; then \
echo $$h > /etc/ansible.hostname; \
else \
if [ ! -s /etc/ansible.hostname ]; then \
hostname > /etc/ansible.hostname; \
fi; \
fi
$(GITCONFIG): defaults/gitconfig
@cp $< $@
.PHONY: dev
dev:
ansible-playbook -i localhost, development.yml -e devmachine=true
cloudflare: group_vars/all/cloudflare.yaml
group_vars/all/cloudflare.yaml: config/cloudflare-ipv4 config/cloudflare-ipv6
(echo -e "---\ncloudflareips:"; for f in $^; do for ip in $$(cat $$f); do echo " - \"$$ip\" "; done; done) > $@
config/cloudflare-ipv%:
wget -O $@ 'https://www.cloudflare.com/ips-v$*/'
.PHONY: sysprep
sysprep: /etc/rc.local
apt-get -y autoremove --purge
apt-get -y remove --purge $$(dpkg -l | awk '/^r/ { print $$2 }')
apt-get clean
rm -rf /var/lib/systemd/random-seed /tmp/* /var/tmp/* /var/cache/* /etc/ssh/*key* /root/.bash_history /root/.cache /var/cache/apt/archives/*
cat /dev/zero > /bigzero || rm -f /bigzero
fstrim -a || echo "No fstrim?"
sync
poweroff
/etc/rc.local: scripts/rc.local
cp $< $@ && chmod 755 $<
ROLEPATHS=$(addsuffix /README.md,$(addprefix ~/.ansible/roles/,$(ANSROLES)))
COLLPATHS=$(addprefix ~/.ansible/collections/ansible_collections/,$(ANSCOLL))
.PHONY: ansible-collections
ansible-collections: $(ANSBIN) $(ROLEPATHS) $(COLLPATHS)
~/.ansible/roles/%/README.md:
@ansible-galaxy role install $*
~/.ansible/collections/ansible_collections/%:
@ansible-galaxy collection install $(subst /,.,$*)