This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
forked from DisasteR/docker-ansible-alpine
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathentrypoint
executable file
·56 lines (48 loc) · 1.5 KB
/
entrypoint
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
#!/bin/sh
#
# Simple wrapper for executing ansible-galaxy and ansible-playbook.
#
# USAGE:
# ansible-playbook-wrapper [other ansible-playbook arguments]
#
# ENVIRONMENT VARIABLES:
#
# - PIP_REQUIREMENTS: pip requirements filename;
# default = "requirements.txt"
# - ANSIBLE_REQUIREMENTS: ansible requirements filename;
# default = "requirements.yml"
# - DEPLOY_KEY deploy key (private)
# Rotate ansible log if exist
if [ -f "ansible.log" ]; then
DATE_LOG=$(date -d "$(head -1 ansible.log | cut -d, -f1 )" +%Y%m%d-%H%M%S) 2>/dev/null
if [ -n "$DATE_LOG" ]; then
mv ansible.log ansible-${DATE_LOG}.log
gzip ansible-${DATE_LOG}.log &
fi
fi
# Optional deploy key
if [ ! -z "$DEPLOY_KEY" ] && [ ! -f "/root/.ssh/id_rsa" ]; then
mkdir -p /root/.ssh/
echo "${DEPLOY_KEY}" > /root/.ssh/id_rsa
chmod 0600 /root/.ssh/id_rsa
fi
# Loadkey into ssh-agent if key exist
if [ -f "/root/.ssh/id_rsa" ]; then
eval $(ssh-agent)
ssh-add /root/.ssh/id_rsa
fi
# install pip requirements, if any
if [ -z "$PIP_REQUIREMENTS" ]; then
PIP_REQUIREMENTS=requirements.txt
fi
if [ -f "$PIP_REQUIREMENTS" ]; then
pip3 install --upgrade -r $PIP_REQUIREMENTS
fi
# install Galaxy roles, if any
if [ -z "$ANSIBLE_REQUIREMENTS" ]; then
ANSIBLE_REQUIREMENTS=requirements.yml
fi
if [ -f "$ANSIBLE_REQUIREMENTS" ]; then
ansible-galaxy install $ANSIBLE_GALAXY_PARAM -r $ANSIBLE_REQUIREMENTS
fi
exec "$@"