FROM alpine:3.19
ENV ANSIBLE_NOCOLOR true
ENV ANSIBLE_SSH_RETRIES 3
ENV PIP_BREAK_SYSTEM_PACKAGES 1
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ansible/.local/bin
RUN \
apk update --no-cache && \
apk upgrade --no-cache && \
apk add --no-cache sshpass bash curl python3 py3-pip openssh-client && \
addgroup -S appgroup -g 1000 && \
adduser -s /bin/bash -S ansible -G appgroup -u 1000 && \
mkdir -p /ansible && \
chown -R ansible:appgroup /ansible && \
su ansible -c 'python3 -m pip install --user ansible-core==2.xx ansible-compat' && \
su ansible -c '$HOME/.local/bin/ansible-galaxy collection install community.general ansible.posix'
USER ansible
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ansible/.local/bin
WORKDIR /ansible
ENTRYPOINT ["/bin/bash"]
Change Ansible version at “ansible-core==2.x” e.g. “ansible-core==2.14.15” and that’s all.
It may not a best way to run Ansible ,but it helps me a lot.
check Ansible version at: https://github.com/ansible/ansible/tags