add entrypoint to ansible
This commit is contained in:
parent
5260be217b
commit
f2aca9d115
|
@ -62,7 +62,9 @@ ENV ANSIBLE_LIBRARY /ansible/library
|
|||
|
||||
WORKDIR /ansible/playbooks
|
||||
|
||||
ENTRYPOINT ["ansible-playbook"]
|
||||
COPY ./.containers/apps/ansible/entrypoint.sh /entrypoint.sh
|
||||
|
||||
CMD ["/entrypoint.sh"]
|
||||
|
||||
LABEL "maintainer"="TrueCharts <info@truecharts.org>"
|
||||
LABEL "authors"="TrueCharts <info@truecharts.org>"
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#!/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 "$@"
|
Loading…
Reference in New Issue