-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Upgraded to Python 3.12 - Upgraded to Ansible 8.5.0 - Renamed the `run` script to `kineticcafe-ansible` and fixed several issues: - Bash 4 or later is required for associative array support. Ensured that this would be respected on macOS by using `/usr/bin/env bash` instead of `/bin/bash`. - Updated the script to use the current version of the image. - Fixed various issues with file and directory mounts. Many more mountable files (`--become-password-file`, etc.) are supported than `--vault-password-file`. Note that not _all_ possible file parameters are supported, such as `--module-paths` or `--extra-vars @file`. Pull requests for supporting these would be considered. - Fixed an overzealous application of `--ask-vault-password`, even for commands that could not use it. - Changed the `sh` subcommand to execute `bash` and added `bash` as a known subcommand. - Added support for deriving the entry point from `basename $0`. - Updated the Docker image to use HEREDOC. - Added `less`, `nano`, and `vim-nox` packages. - Added an `install` script to install `kineticcafe-ansible` and optional symlinks.
- Loading branch information
1 parent
578cadd
commit 0b23928
Showing
9 changed files
with
789 additions
and
233 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
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
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,144 @@ | ||
#! /usr/bin/env bash | ||
|
||
readonly url=https://raw.githubusercontent.com/KineticCafe/docker-ansible/main/kineticcafe-ansible | ||
declare script | ||
script="$(basename "${url}")" | ||
readonly script | ||
|
||
declare -a symlinked_commands | ||
symlinked_commands=( | ||
ansible ansible-community ansible-config | ||
ansible-connection ansible-console ansible-doc | ||
ansible-galaxy ansible-inventory ansible-playbook | ||
ansible-pull ansible-test ansible-vault | ||
) | ||
readonly symlinked_commands | ||
|
||
# equivalent to readlink -f | ||
canonicalize() { | ||
local t | ||
t="$1" | ||
|
||
cd "$(dirname "${t}")" || return 1 | ||
t="$(basename "${t}")" | ||
|
||
while [[ -L "${t}" ]]; do | ||
t="$(readlink "${t}")" | ||
cd "$(dirname "${t}")" || return 1 | ||
t="$(basename "${t}")" | ||
done | ||
|
||
echo "$(pwd -P)/${t}" | ||
} | ||
|
||
usage() { | ||
cat <<USAGE | ||
usage: $(basename "$0") [--no-symlinks|-S] [--force|-f] [--verbose|-v] TARGET | ||
$(basename "$0") --help | -h | -? | ||
Installs the ${script} script to TARGET. Installation will be skipped | ||
if the TARGET/${script} already exists and --force is not supplied. | ||
Unless --no-symlinks is provided, it will also attempt to install symlinks for | ||
Ansible commands: | ||
ansible ansible-community ansible-config | ||
ansible-connection ansible-console ansible-doc | ||
ansible-galaxy ansible-inventory ansible-playbook | ||
ansible-pull ansible-test ansible-vault | ||
Symlink installation will be skipped if the file already exists and is not | ||
already a symlink to TARGET/${script} and --force is not supplied. | ||
USAGE | ||
} | ||
|
||
maybe-verbose() { | ||
if "${verbose}"; then | ||
set -x && "${@}" && set +x | ||
else | ||
"${@}" | ||
fi | ||
} | ||
|
||
declare force install_symlinks no_download target target_script verbose | ||
force=false | ||
install_symlinks=true | ||
no_download=false | ||
verbose=false | ||
|
||
while (($#)); do | ||
case "$1" in | ||
--force | -f) force=true ;; | ||
--verbose | -v) verbose=true ;; | ||
--no-download) no_download=true ;; | ||
--no-symlinks | -S) install_symlinks=false ;; | ||
--help | -h | -?) | ||
usage | ||
exit 0 | ||
;; | ||
*) | ||
if [[ ! -d "$1" ]]; then | ||
printf >&2 "error: '%s' is not a directory\n\n" "$1" | ||
usage >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ -n "${target}" ]]; then | ||
printf >&2 "warning: target '%s' is being replaced with '%s'" \ | ||
"$target" "$1" | ||
fi | ||
|
||
target="$1" | ||
;; | ||
esac | ||
|
||
shift | ||
done | ||
|
||
if [[ -z "${target}" ]]; then | ||
printf >&2 "error: no TARGET provided\n\n" | ||
usage >&2 | ||
exit 1 | ||
fi | ||
|
||
target_script="${target}/${script}" | ||
|
||
download-script() { | ||
if ! curl -sSL --fail "${url}" -o "${target_script}"; then | ||
echo >&2 "error: could not download ${url} into ${target_script}." | ||
exit 1 | ||
fi | ||
} | ||
|
||
if "${no_download}"; then | ||
if ! [[ -x "${target_script}" ]]; then | ||
echo >&2 "error: ${target_script} does not exist and no download is set." | ||
fi | ||
elif [[ -x "${target_script}" ]]; then | ||
if ! "${force}"; then | ||
echo >&2 "error: ${target_script} already exists." | ||
exit 1 | ||
fi | ||
|
||
maybe-verbose download-script | ||
|
||
[[ -x "${target_script}" ]] || maybe-verbose chmod +x "${target_script}" | ||
fi | ||
|
||
"${install_symlinks}" || exit 0 | ||
|
||
declare symlinked_command target_command canonical_target | ||
|
||
for symlinked_command in "${symlinked_commands[@]}"; do | ||
target_command="${target}/${symlinked_command}" | ||
|
||
if [[ -f "${target_command}" ]]; then | ||
canonical_target="$(canonicalize "${target_command}")" | ||
|
||
if [[ "${canonical_target}" != "${target_script}" ]]; then | ||
"${force}" || continue | ||
fi | ||
fi | ||
|
||
maybe-verbose ln -sf "${target_script}" "${target_command}" | ||
done |
Oops, something went wrong.