forked from cytopia/ansible-debian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
160 lines (136 loc) · 6.14 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
DIR = .
FILE = Dockerfile
IMAGE = cytopia/ansible-debian
TAG = latest
# Ansible variables
VERBOSE=
PROFILE=cytopia-t470p
ARG=
.PHONY: help build-docker test-docker-full test-docker-random test-docker-single itest-docker-full itest-docker-random itest-docker-single
#--------------------------------------------------------------------------------------------------
# Default Target
#--------------------------------------------------------------------------------------------------
help:
@echo "################################################################################"
@echo "# #"
@echo "# Debian Provisioning with Ansible #"
@echo "# #"
@echo "################################################################################"
@echo
@echo
@echo "------------------------------------------------------------"
@echo " Run tests in Docker"
@echo "------------------------------------------------------------"
@echo
@echo "build-docker Build the testing Docker image (happens automatically during tests)"
@echo
@echo "test-docker-docker-full Run a full test in a Docker (requires PROFILE)"
@echo "test-docker-docker-random Run a full randomized test in a Docker (requires PROFILE)"
@echo "test-docker-docker-single Run the test on a single role in a Docker (requires PROFILE and ROLE)"
@echo
@echo "itest-docker-docker-full Interactive version of test-docker-full (requires PROFILE)"
@echo "itest-docker-docker-random Interactive version of test-docker-random (requires PROFILE)"
@echo "itest-docker-docker-single Interactive version of test-docker-single (requires PROFILE and ROLE)"
@echo
@echo
@echo "------------------------------------------------------------"
@echo " Run tests in Vagrant"
@echo "------------------------------------------------------------"
@echo
@echo "------------------------------------------------------------"
@echo " Deploy your host system"
@echo "------------------------------------------------------------"
@echo
#--------------------------------------------------------------------------------------------------
# Tests with Docker
#--------------------------------------------------------------------------------------------------
build-docker:
docker build -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)
# Automated tests
test-docker-full: build-docker
docker run --rm -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -t $(IMAGE)
test-docker-random: build-docker
docker run --rm -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -e random=1 -t $(IMAGE)
test-docker-single: build-docker
docker run --rm -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -e tag=$(ROLE) -t $(IMAGE)
# Interactive tests
# When inside the Container execute: ./run-tests.sh
itest-docker-full: build-docker
docker run -it --rm --entrypoint=bash -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -t $(IMAGE)
itest-docker-random: build-docker
docker run -it --rm --entrypoint=bash -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -e random=1 -t $(IMAGE)
itest-docker-single: build-docker
docker run -it --rm --entrypoint=bash -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -e tag=$(ROLE) -t $(IMAGE)
#--------------------------------------------------------------------------------------------------
# Tests with Vagrant
#--------------------------------------------------------------------------------------------------
# Test your profile with Vagrant
test-vagrant:
vagrant rsync
PROFILE=$(PROFILE) vagrant up --provision
#--------------------------------------------------------------------------------------------------
# Deploy Targets
#--------------------------------------------------------------------------------------------------
# (Step 1/4) [requires root] Ensure required software is present
deploy-init:
ifneq ($(USER),root)
$(error Target 'deploy-init' must be run as root or with sudo)
endif
DEBIAN_FRONTEND=noninteractive apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -qq -q --no-install-recommends --no-install-suggests \
python-apt \
python-dev \
python-jmespath \
python-pip \
python-setuptools
pip install wheel
pip install ansible
# (Step 2/4) Add new Debian sources
deploy-apt-sources:
ifeq ($(USER),root)
$(error Target 'deploy-apt-sources' must be run as normal user without sudo)
endif
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff -t bootstrap-system --ask-become-pass
# (Step 3/4) [requires root] Adist-upgrade your system
deploy-dist-upgrade:
ifneq ($(USER),root)
$(error Target 'deploy-dist-upgrade' must be run as root or with sudo)
endif
DEBIAN_FRONTEND=noninteractive apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -qq -y
# (Step 4/4) Deploy your system
deploy-tools:
ifeq ($(USER),root)
$(error Target 'deploy-tools' must be run as normal user without sudo)
endif
ifndef ROLE
ifndef IGNORE
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff --ask-become-pass $(ARG)
else
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff --ask-become-pass $(ARG) --skip-tags=$(IGNORE)
endif
else
ifndef IGNORE
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff --ask-become-pass $(ARG) -t $(ROLE)
else
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff --ask-become-pass $(ARG) -t $(ROLE) --skip-tags=$(IGNORE)
endif
endif
# Checkmode to test against currently installed tools
diff-tools:
ifeq ($(USER),root)
$(error Target 'diff-tools' must be run as normal user without sudo)
endif
ifndef ROLE
ifndef IGNORE
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff --check --ask-become-pass $(ARG)
else
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff --check --ask-become-pass $(ARG) --skip-tags=$(IGNORE)
endif
else
ifndef IGNORE
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff --check --ask-become-pass $(ARG) -t $(ROLE)
else
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff --check --ask-become-pass $(ARG) -t $(ROLE) --skip-tags=$(IGNORE)
endif
endif