-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8c5241
commit e2e62ee
Showing
5 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Utils for use during / after installation of image | ||
================================================== | ||
|
||
Contains image entrypoint as well as any other scripts useful | ||
in aiding an image run. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash -e | ||
# | ||
# This file serves as the main entrypoint to the openshift-ansible image. | ||
# Contains setup logic and runs a user-specified playbook via the | ||
# $PLAYBOOK_FILE environment variable. | ||
# | ||
# For more information see the documentation: | ||
# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md | ||
# | ||
|
||
# SOURCE and HOME DIRECTORY: /opt/app-root/src | ||
|
||
USER_ID=$(id -u) | ||
GROUP_ID=$(id -g) | ||
|
||
# Patch /etc/passwd file with the local user info. | ||
# A user (name) must be defined in this file in order for | ||
# the `ssh` command to work within the created container. | ||
sed "s@${USER_NAME}:x:\${USER_ID}:\${GROUP_ID}@${USER_NAME}:x:${USER_ID}:${GROUP_ID}@g" ${APP_ROOT}/etc/passwd.template > /etc/passwd | ||
|
||
INVENTORY="$(mktemp)" | ||
if [[ -v INVENTORY_FILE ]]; then | ||
# If the pointed inventory has execute/search perms we can assume it | ||
# contains a dynamic inventory and we use it directly. | ||
# Otherwise we make a copy so that ALLOW_ANSIBLE_CONNECTION_LOCAL below | ||
# does not attempt to modify the original | ||
if [[ -x ${INVENTORY_FILE} ]]; then | ||
INVENTORY="${INVENTORY_FILE}" | ||
else | ||
cp ${INVENTORY_FILE} ${INVENTORY} | ||
fi | ||
elif [[ -v INVENTORY_URL ]]; then | ||
curl -o ${INVENTORY} ${INVENTORY_URL} | ||
elif [[ -v DYNAMIC_SCRIPT_URL ]]; then | ||
curl -o ${INVENTORY} ${DYNAMIC_SCRIPT_URL} | ||
chmod 755 ${INVENTORY} | ||
else | ||
echo "One of INVENTORY_FILE, INVENTORY_URL or DYNAMIC_SCRIPT_URL must be provided" | ||
exit 1 | ||
fi | ||
INVENTORY_ARG="-i ${INVENTORY}" | ||
|
||
if [[ "$ALLOW_ANSIBLE_CONNECTION_LOCAL" = false ]]; then | ||
sed -i s/ansible_connection=local// ${INVENTORY} | ||
fi | ||
|
||
if [[ -v VAULT_PASS ]]; then | ||
VAULT_PASS_FILE=.vaultpass | ||
echo ${VAULT_PASS} > ${VAULT_PASS_FILE} | ||
VAULT_PASS_ARG="--vault-password-file ${VAULT_PASS_FILE}" | ||
fi | ||
|
||
WORK_DIR=${WORK_DIR:-${APP_HOME}} | ||
|
||
cd ${WORK_DIR} | ||
|
||
if [[ -z PLAYBOOK_FILE ]]; then | ||
exec /usr/bin/usage | ||
exit 0 | ||
fi | ||
|
||
ansible-playbook ${INVENTORY_ARG} ${VAULT_PASS_ARG} ${OPTS} ${PLAYBOOK_FILE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#!/bin/bash -e | ||
cat <<EOF | ||
The openshift/openshift-ansible image provides several options to control the behaviour of the containers. | ||
For more details on these options see the documentation: | ||
|
||
https://github.com/openshift/openshift-ansible/blob/master/README_CONTAINER_IMAGE.md | ||
|
||
At the very least, when running a container using this image you must specify: | ||
|
||
An inventory file. This can be mounted inside the container as a volume and specified with the INVENTORY_FILE environment variable. Alternatively you can serve the inventory file from a web server and use the INVENTORY_URL environment variable to fetch it. | ||
ssh keys so that Ansible can reach your hosts. These should be mounted as a volume under /opt/app-root/src/.ssh | ||
The playbook to run. This is set using the PLAYBOOK_FILE environment variable. If you don't specify a playbook the openshift_facts playbook will be run, collecting and showing facts about your OpenShift environment. | ||
Here is an example of how to run a containerized openshift-ansible playbook that will check the expiration dates of OpenShift's internal certificates using the openshift_certificate_expiry role. The inventory and ssh keys are mounted as volumes (the latter requires setting the uid in the container and SELinux label in the key file via :Z so they can be accessed) and the PLAYBOOK_FILE environment variable is set to point to an example certificate check playbook that is already part of the image: | ||
|
||
docker run -u `id -u` \ | ||
-v $HOME/.ssh/id_rsa:/opt/app-root/src/.ssh/id_rsa:Z,ro \ | ||
-v /etc/ansible/hosts:/tmp/inventory:ro \ | ||
-e INVENTORY_FILE=/tmp/inventory \ | ||
-e OPTS="-v" \ | ||
-e PLAYBOOK_FILE=playbooks/certificate_expiry/default.yaml \ | ||
openshift/origin-ansible | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
set -x | ||
chown -R ${USER_UID}:0 ${APP_ROOT} | ||
chmod -R g+rw ${APP_ROOT} /etc/passwd | ||
find ${APP_ROOT} -type d -exec chmod g+x {} + |