A production-ready Docker image for Ansible Core with HashiCorp Vault support and 10+ pre-installed collections for simple automation, management configuration, and more.
- Multiple Ansible Core versions: Choose between stable (2.18) or latest (2.19)
- HashiCorp Vault integration: Built-in
hvaclibrary for seamless secrets management - 10+ Pre-installed collections: Ready-to-use collections
- Lightweight: Based on Python slim images
- CI/CD ready: Perfect for automated pipelines
| Image Tag | Python Version | Ansible Core |
|---|---|---|
latest, 2, 2.19, 2.19.4 |
3.12 | 2.19.4 |
2.18, 2.18.11 |
3.11 | 2.18.11 |
Run an Ansible ad-hoc command:
docker run --rm ghcr.io/optimode/ansible-core:latest ansible --versionRun a playbook from your local directory:
docker run --rm \
-v $(pwd):/workspace \
ghcr.io/optimode/ansible-core:latest \
ansible-playbook playbook.ymlStart an interactive session:
docker run --rm -it \
-v $(pwd):/workspace \
ghcr.io/optimode/ansible-core:latestThis image comes with 15+ Ansible collections covering a wide range of platforms and technologies:
- Docker:
community.docker - Podman:
containers.podman
- MySQL:
community.mysql - PostgreSQL:
community.postgresql - MongoDB:
community.mongodb
- HashiCorp Vault:
community.hashi_vault - Cryptography:
community.crypto
- Proxmox:
community.proxmox
View complete collection list
ansible.netcommon, ansible.posix, ansible.utils, community.crypto,
community.dns,community.docker, community.general, community.hashi_vault,
community.mongodb, community.mysql,community.postgresql, community.proxmox,
community.proxysql,community.routeros, containers.podman,
Use the provided build framework: (optibuild)[https://github.com/optimode/optibuild] Install optibuild, create or modify build.conf file.
Only build:
/path/to/optibuild --verbose -c /path/to/ansible-core/build.conf buildBuild a specific version, modify build.conf or create an additional build-specific-version.conf file.
/path/to/optibuild --verbose -c /path/to/ansible-core/build-specific-version.conf build| Argument | Description | Required | Default |
|---|---|---|---|
PYTHON_VERSION |
Python base image version | No | 3.11 |
ANSIBLE_VERSION |
Ansible Core version to install | Yes | - |
URL |
Project URL (OCI label) | No | - |
SOURCE |
Source repository (OCI label) | No | - |
BUILD_DATE |
Build timestamp (OCI label) | No | - |
AUTHORS |
Image authors (OCI label) | No | - |
VENDOR |
Vendor name (OCI label) | No | - |
REVISION |
Git commit hash (OCI label) | No | - |
Mount your SSH keys for remote host access:
docker run --rm \
-v $(pwd):/workspace \
-v ~/.ssh:/home/ansible/.ssh:ro \
ghcr.io/optimode/ansible-core:latest \
ansible-playbook -i inventory.ini playbook.ymlPass vault password via file:
docker run --rm \
-v $(pwd):/workspace \
-v $(pwd)/.vault-pass:/home/ansible/.vault-pass:ro \
ghcr.io/optimode/ansible-core:latest \
ansible-playbook --vault-password-file=/home/ansible/.vault-pass playbook.ymlOr via environment variable:
docker run --rm \
-v $(pwd):/workspace \
-e ANSIBLE_VAULT_PASSWORD=mysecret \
ghcr.io/optimode/ansible-core:latest \
ansible-playbook playbook.ymlThe image includes hvac library for Vault integration. Configure via environment:
docker run --rm \
-v $(pwd):/workspace \
-e VAULT_ADDR=https://vault.example.com:8200 \
-e VAULT_TOKEN=s.xxxxxxxxxxxxxx \
ghcr.io/optimode/ansible-core:latest \
ansible-playbook playbook.ymlUse dynamic inventory or custom inventory files:
docker run --rm \
-v $(pwd):/workspace \
ghcr.io/optimode/ansible-core:latest \
ansible-playbook -i inventory/production.yml deploy.ymlInstall collections at runtime:
docker run --rm \
-v $(pwd):/workspace \
ghcr.io/optimode/ansible-core:latest \
bash -c "ansible-galaxy collection install my.collection && ansible-playbook playbook.yml"Or build a custom image:
FROM ghcr.io/optimode/ansible-core:latest
COPY my-collections.yml /tmp/
RUN ansible-galaxy collection install -r /tmp/my-collections.ymldocker run --rm \
--user $(id -u):$(id -g) \
-v $(pwd):/workspace \
ghcr.io/optimode/ansible-core:latest \
ansible-playbook playbook.ymlname: Deploy with Ansible
on: [push]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Ansible Playbook
run: |
docker run --rm \
-v ${{ github.workspace }}:/workspace \
-e ANSIBLE_VAULT_PASSWORD=${{ secrets.VAULT_PASSWORD }} \
ghcr.io/optimode/ansible-core:latest \
ansible-playbook -i inventory/production.yml deploy.ymldeploy:
image: ghcr.io/optimode/ansible-core:latest
script:
- ansible-playbook -i inventory/production.yml deploy.yml
only:
- mainCommon Ansible environment variables you can use:
| Variable | Description | Example |
|---|---|---|
ANSIBLE_CONFIG |
Path to ansible.cfg | /workspace/ansible.cfg |
ANSIBLE_INVENTORY |
Default inventory path | /workspace/inventory |
ANSIBLE_VAULT_PASSWORD |
Vault password | mysecretpass |
ANSIBLE_HOST_KEY_CHECKING |
SSH host key checking | False |
ANSIBLE_STDOUT_CALLBACK |
Output format | yaml |
ANSIBLE_FORCE_COLOR |
Force colored output | true |
VAULT_ADDR |
HashiCorp Vault address | https://vault:8200 |
VAULT_TOKEN |
Vault authentication token | s.xxxxx |
# Create a simple playbook
cat > playbook.yml <<EOF
---
- hosts: localhost
tasks:
- name: Print Ansible version
debug:
msg: "Running Ansible {{ ansible_version.full }}"
EOF
# Run it
docker run --rm -v $(pwd):/workspace ghcr.io/optimode/ansible-core:latest \
ansible-playbook playbook.ymlansible- Full Ansible package with coreansible-lint- Best practices checker for Ansiblehvac- HashiCorp Vault client libraryjmespath- JSON query language for data parsingnetaddr- Network address manipulationdocker- Docker SDK for Python
git- Version control systemopenssh-client- SSH client for remote connectionssshpass- Non-interactive SSH password authenticationrsync- Fast file synchronization tool
If you encounter permission errors with mounted volumes:
# Run as your current user
docker run --rm --user $(id -u):$(id -g) -v $(pwd):/workspace ghcr.io/optimode/ansible-core:latest ansible-playbook playbook.ymlEnable SSH debugging:
docker run --rm -v $(pwd):/workspace ghcr.io/optimode/ansible-core:latest \
ansible-playbook -vvv playbook.ymlVerify installed collections:
docker run --rm ghcr.io/optimode/ansible-core:latest ansible-galaxy collection listInstall missing collection:
docker run --rm ghcr.io/optimode/ansible-core:latest \
ansible-galaxy collection install namespace.collectionContributions are welcome! Please feel free to submit a Pull Request.
To add collections to the base image, update requirements-collections.yml.
This project is licensed under the MIT License - see the LICENSE file for details.
Optimode (Laszlo Malina) GitHub: @optimode
If you encounter issues or have questions:
- Check the Troubleshooting section
- Review Ansible documentation
- Open an issue on GitHub
Built with ❤️ by Optimode