Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit ef03e3d

Browse files
committed
5.0.0 / 2023-11-03
- 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.
1 parent 578cadd commit ef03e3d

File tree

9 files changed

+789
-233
lines changed

9 files changed

+789
-233
lines changed

.github/workflows/build-test-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ jobs:
2525
push: false
2626
tags: kineticcafe/ansible:test
2727

28-
- run: ./run --version
28+
- run: ./kineticcafe-ansible --version
2929
env:
3030
IMAGE: kineticcafe/ansible:test

Changelog.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# [ghcr.io/]kineticcafe/ansible Changelog
22

3+
## 5.0.0 / 2023-11-03
4+
5+
- Upgraded to Python 3.12
6+
7+
- Upgraded to Ansible 8.5.0
8+
9+
- Renamed the `run` script to `kineticcafe-ansible` and fixed several issues:
10+
11+
- Bash 4 or later is required for associative array support. Ensured that
12+
this would be respected on macOS by using `/usr/bin/env bash` instead of
13+
`/bin/bash`.
14+
15+
- Updated the script to use the current version of the image.
16+
17+
- Fixed various issues with file and directory mounts. Many more mountable
18+
files (`--become-password-file`, etc.) are supported than
19+
`--vault-password-file`. Note that not _all_ possible file parameters are
20+
supported, such as `--module-paths` or `--extra-vars @file`. Pull requests
21+
for supporting these would be considered.
22+
23+
- Fixed an overzealous application of `--ask-vault-password`, even for
24+
commands that could not use it.
25+
26+
- Changed the `sh` subcommand to execute `bash` and added `bash` as a known
27+
subcommand.
28+
29+
- Added support for deriving the entry point from `basename $0`.
30+
31+
- Updated the Docker image to use HEREDOC.
32+
33+
- Added `less`, `nano`, and `vim-nox` packages.
34+
35+
- Added an `install` script to install `kineticcafe-ansible` and optional
36+
symlinks.
37+
338
## 4.0.0 / 2023-08-04
439

540
- Upgraded to Ansible 8.2.0

Dockerfile

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
FROM python:3.12-slim-bullseye AS builder
1+
# syntax=docker/dockerfile:1
2+
3+
FROM python:3.12-slim-bookworm AS builder
24

35
ENV LC_ALL=C.UTF-8 \
46
LANG=C.UTF-8 \
57
EDITOR=nano
68

7-
RUN apt-get -qqy update \
8-
&& apt-get -qqy upgrade \
9-
&& apt-get -qqy --no-install-recommends install \
10-
build-essential \
11-
python-dev \
12-
libffi-dev \
13-
rustc \
14-
&& adduser --disabled-password --gecos '' ansible \
15-
&& python3 -m pip install pip --upgrade \
16-
&& mkdir -p /opt/ansible \
17-
&& chown -R ansible:ansible /opt/ansible
9+
RUN <<BUILD_SETUP
10+
set -eux
11+
12+
apt-get -y update
13+
apt-get -y upgrade
14+
apt-get -y --no-install-recommends install \
15+
build-essential \
16+
python3-dev \
17+
libffi-dev \
18+
rustc
19+
20+
adduser --disabled-password --gecos '' ansible
21+
python3 -m pip install pip --upgrade
22+
23+
mkdir -p /opt/ansible
24+
chown -R ansible:ansible /opt/ansible
25+
BUILD_SETUP
1826

1927
USER ansible
2028

@@ -26,16 +34,30 @@ WORKDIR /opt/ansible
2634

2735
ADD pyproject.toml pdm.lock /opt/ansible/
2836

29-
RUN python3 -m pip install --user pdm \
30-
&& /home/ansible/.local/bin/pdm sync --clean --production --no-editable
37+
RUN <<BUILD_PROJECT
38+
set -eux
39+
40+
python3 -m pip install --user pdm
41+
/home/ansible/.local/bin/pdm sync --clean --production --no-editable
42+
BUILD_PROJECT
43+
44+
FROM python:3.12-slim-bookworm AS runtime
45+
46+
RUN <<SETUP
47+
set -eux
48+
49+
apt-get -y update
50+
apt-get -y upgrade
51+
apt-get -y --no-install-recommends install \
52+
less \
53+
nano \
54+
vim-nox
3155

32-
FROM python:3.12-slim-bullseye AS runtime
56+
adduser --disabled-password --gecos '' ansible
3357

34-
RUN apt-get -qqy update \
35-
&& apt-get -qqy upgrade \
36-
&& adduser --disabled-password --gecos '' ansible \
37-
&& mkdir -p /opt/ansible \
38-
&& chown -R ansible:ansible /opt/ansible
58+
mkdir -p /opt/ansible
59+
chown -R ansible:ansible /opt/ansible
60+
SETUP
3961

4062
COPY --chown=ansible:ansible --from=builder /opt/ansible /opt/ansible
4163

README.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ This is a simple Docker container that contains [Ansible][]. It has been created
44
so that it's easier to work with `ansible-playbook` without going through the
55
effort of installing it on various systems.
66

7-
The image is based on Debian Bullseye (slim) and includes:
7+
The image is based on Debian Bookworm (slim) and includes:
88

9-
- Ansible 7 (7.7.0 or later)
10-
- Python 3.11
9+
- Ansible 8.5.0
10+
- Python 3.12
1111

1212
These images can be pulled either from Docker Hub
13-
(`kineticcafe/sqitch-pgtap:2.1`) or the GitHub Container Registry
14-
(`ghcr.io/kineticcafe/sqitch-pgtap:2.1`).
13+
(`kineticcafe/ansible:5.0`) or the GitHub Container Registry
14+
(`ghcr.io/kineticcafe/ansible:5.0`).
1515

1616
## Support
1717

@@ -20,24 +20,52 @@ Tests have been made on Ubuntu 18 and macOS 13 (Apple Silicon).
2020
Because of recent changes to cryptographic packages in Python, support for
2121
linux/arm/v7 has been dropped.
2222

23-
## `run` script Commands
23+
## `kineticcafe-ansible` script Commands
2424

25-
The `run` script is recommended for running everything as it manages environment
26-
variable configuration for each run. The `run` script will pull from
27-
`ghcr.io/kineticcafe/ansible:3.1` by default; this can be overridden by
28-
using `$IMAGE`:
25+
The `kineticcafe-ansible` script is recommended for running everything as it
26+
manages environment variable configuration for each run. The
27+
`kineticcafe-ansible` script will pull from `ghcr.io/kineticcafe/ansible:5.0` by
28+
default; this can be overridden by using `$IMAGE`:
2929

3030
```sh
31-
$ IMAGE=kineticcafe/ansible:latest ./run --version
31+
$ IMAGE=kineticcafe/ansible:latest ./kineticcafe-ansible --version
3232
```
3333

34+
### Installing `kinetic-ansible`
35+
36+
`kinetic-ansible` can be installed with symlinks using the `install` script:
37+
38+
```sh
39+
curl -sSL --fail \
40+
https://raw.githubusercontent.com/KineticCafe/docker-ansible/main/install |
41+
bash -s -- ~/.local/bin
42+
```
43+
44+
Replace `~/.local/bin` with your preferred binary directory.
45+
46+
By default, it will download `kinetic-ansible` from GitHub and install it in the
47+
provided `TARGET` and make symbolic links for the following Ansible commands:
48+
`ansible`, `ansible-community`, `ansible-config`, `ansible-connection`,
49+
`ansible-console`, `ansible-doc`, `ansible-galaxy`, `ansible-inventory`,
50+
`ansible-playbook`, `ansible-pull`, `ansible-test`, and `ansible-vault`.
51+
Symbolic link creation will not overwrite files or symbolic links to locations
52+
_other_ than `TARGET/kinetic-ansible`.
53+
54+
`--no-symlinks` (`-S`) may be specified to skip symbolic link creation entirely.
55+
56+
`--force` (`-f`) may be specified to install `kinetic-ansible` even if it already
57+
exists, and to overwrite files and non-`TARGET/kinetic-ansible` symbolic links.
58+
59+
`--verbose` (`-v`) will turn on trace output of commands.
60+
3461
## Maintenance/Upgrade Instructions
3562

3663
1. Install [pdm][]: `pipx install pdm`.
3764

3865
2. Edit the `Dockerfile` to update the Python version, if required.
3966

40-
3. Edit the `pyproject.toml` to change the dependencies, if required.
67+
3. Edit the `pyproject.toml` to change the dependencies and update the
68+
`project.version`.
4169

4270
4. Run `pdm update`.
4371

install

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#! /usr/bin/env bash
2+
3+
readonly url=https://raw.githubusercontent.com/KineticCafe/docker-ansible/main/kineticcafe-ansible
4+
declare script
5+
script="$(basename "${url}")"
6+
readonly script
7+
8+
declare -a symlinked_commands
9+
symlinked_commands=(
10+
ansible ansible-community ansible-config
11+
ansible-connection ansible-console ansible-doc
12+
ansible-galaxy ansible-inventory ansible-playbook
13+
ansible-pull ansible-test ansible-vault
14+
)
15+
readonly symlinked_commands
16+
17+
# equivalent to readlink -f
18+
canonicalize() {
19+
local t
20+
t="$1"
21+
22+
cd "$(dirname "${t}")" || return 1
23+
t="$(basename "${t}")"
24+
25+
while [[ -L "${t}" ]]; do
26+
t="$(readlink "${t}")"
27+
cd "$(dirname "${t}")" || return 1
28+
t="$(basename "${t}")"
29+
done
30+
31+
echo "$(pwd -P)/${t}"
32+
}
33+
34+
usage() {
35+
cat <<USAGE
36+
usage: $(basename "$0") [--no-symlinks|-S] [--force|-f] [--verbose|-v] TARGET
37+
$(basename "$0") --help | -h | -?
38+
39+
Installs the ${script} script to TARGET. Installation will be skipped
40+
if the TARGET/${script} already exists and --force is not supplied.
41+
42+
Unless --no-symlinks is provided, it will also attempt to install symlinks for
43+
Ansible commands:
44+
45+
ansible ansible-community ansible-config
46+
ansible-connection ansible-console ansible-doc
47+
ansible-galaxy ansible-inventory ansible-playbook
48+
ansible-pull ansible-test ansible-vault
49+
50+
Symlink installation will be skipped if the file already exists and is not
51+
already a symlink to TARGET/${script} and --force is not supplied.
52+
USAGE
53+
}
54+
55+
maybe-verbose() {
56+
if "${verbose}"; then
57+
set -x && "${@}" && set +x
58+
else
59+
"${@}"
60+
fi
61+
}
62+
63+
declare force install_symlinks no_download target target_script verbose
64+
force=false
65+
install_symlinks=true
66+
no_download=false
67+
verbose=false
68+
69+
while (($#)); do
70+
case "$1" in
71+
--force | -f) force=true ;;
72+
--verbose | -v) verbose=true ;;
73+
--no-download) no_download=true ;;
74+
--no-symlinks | -S) install_symlinks=false ;;
75+
--help | -h | -?)
76+
usage
77+
exit 0
78+
;;
79+
*)
80+
if [[ ! -d "$1" ]]; then
81+
printf >&2 "error: '%s' is not a directory\n\n" "$1"
82+
usage >&2
83+
exit 1
84+
fi
85+
86+
if [[ -n "${target}" ]]; then
87+
printf >&2 "warning: target '%s' is being replaced with '%s'" \
88+
"$target" "$1"
89+
fi
90+
91+
target="$1"
92+
;;
93+
esac
94+
95+
shift
96+
done
97+
98+
if [[ -z "${target}" ]]; then
99+
printf >&2 "error: no TARGET provided\n\n"
100+
usage >&2
101+
exit 1
102+
fi
103+
104+
target_script="${target}/${script}"
105+
106+
download-script() {
107+
if ! curl -sSL --fail "${url}" -o "${target_script}"; then
108+
echo >&2 "error: could not download ${url} into ${target_script}."
109+
exit 1
110+
fi
111+
}
112+
113+
if "${no_download}"; then
114+
if ! [[ -x "${target_script}" ]]; then
115+
echo >&2 "error: ${target_script} does not exist and no download is set."
116+
fi
117+
elif [[ -x "${target_script}" ]]; then
118+
if ! "${force}"; then
119+
echo >&2 "error: ${target_script} already exists."
120+
exit 1
121+
fi
122+
123+
maybe-verbose download-script
124+
125+
[[ -x "${target_script}" ]] || maybe-verbose chmod +x "${target_script}"
126+
fi
127+
128+
"${install_symlinks}" || exit 0
129+
130+
declare symlinked_command target_command canonical_target
131+
132+
for symlinked_command in "${symlinked_commands[@]}"; do
133+
target_command="${target}/${symlinked_command}"
134+
135+
if [[ -f "${target_command}" ]]; then
136+
canonical_target="$(canonicalize "${target_command}")"
137+
138+
if [[ "${canonical_target}" != "${target_script}" ]]; then
139+
"${force}" || continue
140+
fi
141+
fi
142+
143+
maybe-verbose ln -sf "${target_script}" "${target_command}"
144+
done

0 commit comments

Comments
 (0)