aboutsummaryrefslogtreecommitdiffhomepage
path: root/mini-debian9
diff options
context:
space:
mode:
Diffstat (limited to 'mini-debian9')
-rw-r--r--mini-debian9/Dockerfile27
-rwxr-xr-xmini-debian9/ansible-playbook-wrapper49
-rw-r--r--mini-debian9/apt-list21
-rwxr-xr-xmini-debian9/install-ansible.sh27
-rwxr-xr-xmini-debian9/prepare-pkg-list.sh37
-rwxr-xr-xmini-debian9/uninstall-ansible.sh21
6 files changed, 182 insertions, 0 deletions
diff --git a/mini-debian9/Dockerfile b/mini-debian9/Dockerfile
new file mode 100644
index 0000000..8de9dd0
--- /dev/null
+++ b/mini-debian9/Dockerfile
@@ -0,0 +1,27 @@
1# Dockerfile for building Debian-based image, via Ansible playbooks.
2#
3# @see http://docs.ansible.com/ansible/intro_installation.html#running-from-source
4#
5# Version 1.0
6#
7
8
9# pull base image
10FROM debian:9
11
12MAINTAINER William Yeh <william.pjyeh@gmail.com>
13
14#ENV APT_LIST apt-list
15
16
17COPY . /tmp
18
19ONBUILD COPY . /tmp
20ONBUILD RUN \
21 cd /tmp && \
22 ./prepare-pkg-list.sh && \
23 ./install-ansible.sh && \
24 ./ansible-playbook-wrapper && \
25 ./uninstall-ansible.sh && \
26 cd / && \
27 rm -rf /tmp/* \ No newline at end of file
diff --git a/mini-debian9/ansible-playbook-wrapper b/mini-debian9/ansible-playbook-wrapper
new file mode 100755
index 0000000..0ba45e6
--- /dev/null
+++ b/mini-debian9/ansible-playbook-wrapper
@@ -0,0 +1,49 @@
1#!/bin/sh
2#
3# Simple wrapper for executing ansible-galaxy and ansible-playbook
4# with local connection.
5#
6# USAGE:
7# ansible-playbook-wrapper [other ansible-playbook arguments]
8#
9# ENVIRONMENT VARIABLES:
10#
11# - REQUIREMENTS: requirements filename; default = "requirements.yml"
12# - PLAYBOOK: playbook filename; default = "playbook.yml"
13# - INVENTORY: inventory filename; default = "/etc/ansible/hosts"
14#
15
16
17#
18# install Galaxy roles, if any
19#
20
21if [ -z "$REQUIREMENTS" ]; then
22 REQUIREMENTS=requirements.yml
23fi
24
25if [ -f "$REQUIREMENTS" ]; then
26 ansible-galaxy install -r $REQUIREMENTS
27fi
28
29
30#
31# execute playbook
32#
33
34if [ -z "$PLAYBOOK" ]; then
35 PLAYBOOK=playbook.yml
36fi
37
38
39if [ -z "$INVENTORY" ]; then
40 exec ansible-playbook \
41 $PLAYBOOK \
42 --connection=local \
43 "$@"
44else
45 exec ansible-playbook \
46 -i $INVENTORY $PLAYBOOK \
47 --connection=local \
48 "$@"
49fi
diff --git a/mini-debian9/apt-list b/mini-debian9/apt-list
new file mode 100644
index 0000000..7f23377
--- /dev/null
+++ b/mini-debian9/apt-list
@@ -0,0 +1,21 @@
1#
2# packages to be installed via APT;
3# lines beginning with "! " (an exclamation mark, followed by a space) will *not* be *uninstalled* afterwards.
4#
5
6
7# common
8#####sudo curl gcc
9
10# ssl
11#####openssl ca-certificates
12
13# python-runtime
14python
15#####python-pip python-yaml
16
17# build-dependencies
18#####python-dev libffi-dev libssl-dev
19
20# may be required by ansible-galaxy
21git \ No newline at end of file
diff --git a/mini-debian9/install-ansible.sh b/mini-debian9/install-ansible.sh
new file mode 100755
index 0000000..6083050
--- /dev/null
+++ b/mini-debian9/install-ansible.sh
@@ -0,0 +1,27 @@
1#!/bin/sh
2#
3# Simple wrapper for installing ansible
4#
5
6
7export DEBIAN_FRONTEND=noninteractive
8
9
10echo "===> Adding prerequisites..."
11
12apt-get update -y
13cat ___APT_INSTALL_LIST | \
14 while read ITEM; do
15 apt-get install -y $ITEM
16 done
17
18
19
20echo "===> Installing Ansible..."
21apt-get install -y ansible
22
23
24
25echo "===> Adding hosts for convenience..." && \
26mkdir -p /etc/ansible && \
27echo 'localhost' > /etc/ansible/hosts
diff --git a/mini-debian9/prepare-pkg-list.sh b/mini-debian9/prepare-pkg-list.sh
new file mode 100755
index 0000000..ce2195d
--- /dev/null
+++ b/mini-debian9/prepare-pkg-list.sh
@@ -0,0 +1,37 @@
1#!/bin/sh
2#
3# Prepare the list of packages to be installed/uninstalled.
4#
5# ENVIRONMENT VARIABLES:
6#
7# - APT_LIST: APT package list; default = "apt-list"
8#
9
10echo "===> Preparing APT package list..."
11
12if [ -z "$APT_LIST" ]; then
13 APT_LIST=apt-list
14fi
15
16if [ -f "$APT_LIST" ]; then
17
18 awk '/^#/ {next} \
19 { split($0,arrayA); \
20 for (i in arrayA) { \
21 if (arrayA[i] == "!") { continue; } \
22 print arrayA[i] \
23 } \
24 }' \
25 $APT_LIST > ___APT_INSTALL_LIST
26
27 awk '/^(#|!)/ {next} \
28 { split($0,arrayA); for (i in arrayA) print arrayA[i] }' \
29 $APT_LIST |
30 awk '{ L[n++] = $0 } \
31 END { while(n--) \
32 print L[n] }' \
33 > ___APT_UNINSTALL_LIST
34
35fi
36#cat ___APT_INSTALL_LIST
37#cat ___APT_UNINSTALL_LIST
diff --git a/mini-debian9/uninstall-ansible.sh b/mini-debian9/uninstall-ansible.sh
new file mode 100755
index 0000000..3573413
--- /dev/null
+++ b/mini-debian9/uninstall-ansible.sh
@@ -0,0 +1,21 @@
1#!/bin/sh
2#
3# Simple wrapper for uninstall ansible and related stuff.
4#
5
6
7echo "===> Removing Ansible..."
8apt-get -f -y --auto-remove remove ansible
9
10echo "===> Removing APT packages..."
11cat ___APT_UNINSTALL_LIST | \
12 while read ITEM; do
13 apt-get -f -y --auto-remove remove $ITEM
14 done
15apt-get clean
16
17
18echo "===> Cleaning up package list..."
19rm -rf /etc/python /etc/python2.7
20rm -rf /etc/ansible /root/.ansible /root/.cache
21rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d /var/cache/* /var/log/*