Why This Error Happens
Ansible changed how it handles modules starting with version 2.10. Previously, Ansible was a "batteries-included" tool where every module was pre-installed. Now, it uses a decentralized model called Collections. If you see this error, your local environment is missing the specific package that contains the Docker modules.
The error ERROR! couldn't resolve module/action 'community.general.docker_container' usually means the community.general collection isn't in your search path. It might be uninstalled, or Ansible is looking in the wrong folder.
Common Root Causes
- Missing Collection: You haven't run the
ansible-galaxyinstall command yet. - Path Mismatch: The collection is installed in
~/.ansible/collections, but your configuration points elsewhere. - Virtual Environment Conflicts: You installed the collection in your system Python, but you're running the playbook inside a
venv. - Namespace Changes: While many Docker modules live in
community.general, some have migrated tocommunity.docker.
Step-by-Step Fixes
1. Install the Collection Manually
The quickest fix is to pull the collection directly from the Ansible Galaxy registry. Open your terminal and run:
ansible-galaxy collection install community.general
Since Docker modules are frequently updated, you might also want the specific Docker collection to avoid future resolution issues:
ansible-galaxy collection install community.docker
2. Use a requirements.yml File
Managing dependencies manually is risky for team projects. Instead, use a requirements.yml file in your project root to track versions. This ensures everyone on your team uses the same environment.
Create requirements.yml with this content:
---
collections:
- name: community.general
version: 8.2.0
- name: community.docker
version: 3.10.0
Install everything at once using the -r flag:
ansible-galaxy collection install -r requirements.yml
3. Verify Your Collection Paths
Sometimes the files are there, but Ansible is looking in the wrong spot. By default, Ansible searches ~/.ansible/collections and /usr/share/ansible/collections. Check your current configuration by running:
ansible --version
Look for the configured module search path line. If you want to keep collections inside your project folder (e.g., in a ./collections directory), update your ansible.cfg file:
[defaults]
collections_path = ./collections:~/.ansible/collections:/usr/share/ansible/collections
4. Handle Python Virtual Environments
Virtual environments (venvs) often cause path confusion. If you use a venv, ensure you install the collections while that environment is active. A common trap is using the system's ansible-galaxy binary to install modules for a venv-based ansible-playbook run.
To be safe, call the galaxy tool through the Python module syntax to ensure it hits the correct environment:
python3 -m ansible galaxy collection install community.general
Confirming the Fix
Check if Ansible now recognizes the module. List all installed collections with this command:
ansible-galaxy collection list
If community.general appears in the list, try a quick ad-hoc test. Run this command to see if Ansible can pull the module documentation:
ansible localhost -m community.general.docker_container --help
If you see a wall of help text instead of an error, you're ready to go.
Troubleshooting Pro-Tips
- Use FQCN: Always use the Fully Qualified Collection Name. Write
community.general.docker_containerinstead of justdocker_container. This prevents naming conflicts. - Check Permissions: If you used
sudoto install Ansible, you might needsudoto install collections globally. However, it is better to install them at the user level to avoid permission headaches. - Air-Gapped Systems: If your server has no internet, download the
.tar.gzfrom the Galaxy website. Install it locally usingansible-galaxy collection install ./my-collection.tar.gz.

