The Error
You run an Ansible playbook and get:
ERROR! couldn't resolve module/action 'community.general.ufw'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/home/user/playbooks/firewall.yml': line 12, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
Or just the shorter version:
ERROR! couldn't resolve module/action 'docker_container'
Either way, the playbook stops dead. Nothing runs.
Root Cause
Starting with Ansible 2.10, many modules were pulled out of the core package and moved into separate collections. If you upgraded from 2.9 or grabbed a playbook from an older tutorial, the module you're calling probably lives in a collection that isn't installed yet.
Three things cause this error most often:
- The collection containing the module isn't installed (e.g.
community.general,community.docker,amazon.aws) - You're using a short module name like
docker_containerinstead of its fully qualified collection name โ FQCN โ likecommunity.docker.docker_container - Ansible is running from a different Python environment than where you installed the collection
Fix 1: Install the Missing Collection
This is the fix for roughly 80% of cases. First, find which collection the module belongs to โ check the Ansible Collections Index or search locally:
ansible-doc -l | grep docker_container
Then install it:
# Install a single collection
ansible-galaxy collection install community.general
# community.docker covers docker_container, docker_image, etc.
ansible-galaxy collection install community.docker
# AWS modules
ansible-galaxy collection install amazon.aws
# Install multiple at once
ansible-galaxy collection install community.general community.docker ansible.posix
Common module-to-collection mappings:
ufw,timezone,htpasswd,git_configโcommunity.generaldocker_container,docker_image,docker_networkโcommunity.dockerec2,s3_bucket,rds_instanceโamazon.awspostgresql_db,postgresql_userโcommunity.postgresqlmysql_db,mysql_userโcommunity.mysqlk8s,helmโkubernetes.core
Fix 2: Use the Fully Qualified Collection Name (FQCN)
Short module names can still fail on Ansible 2.10+ even after installing the collection. The safe move is to switch to FQCN everywhere:
# Before (short name โ unreliable on Ansible 2.10+)
- name: Manage UFW firewall
ufw:
rule: allow
port: 22
# After (FQCN โ always works)
- name: Manage UFW firewall
community.general.ufw:
rule: allow
port: 22
Same fix for Docker:
# Before
- name: Start nginx container
docker_container:
name: nginx
image: nginx:latest
state: started
# After
- name: Start nginx container
community.docker.docker_container:
name: nginx
image: nginx:latest
state: started
Fix 3: Use a requirements.yml for Repeatable Installs
Working on a team project? Don't rely on everyone remembering to install the right collections. Put your dependencies in a requirements.yml file and commit it to the repo:
# requirements.yml
collections:
- name: community.general
version: ">=8.0.0"
- name: community.docker
version: ">=3.0.0"
- name: amazon.aws
version: ">=7.0.0"
Install everything with one command:
ansible-galaxy collection install -r requirements.yml
Add this as the first step in your CI/CD pipeline, before any playbook runs.
Fix 4: Wrong Python/Ansible Environment
Still getting the error after installing the collection? Ansible might be picking up a different Python environment โ one where the collection isn't installed.
# See which ansible binary is actually running
which ansible
# List installed collections and their paths
ansible-galaxy collection list
# Using a virtualenv? Activate it first, then reinstall
source /path/to/venv/bin/activate
ansible-galaxy collection install community.general
By default, collections install to one of these locations:
~/.ansible/collections/โ per-user/usr/share/ansible/collections/โ system-wide./collections/โ project-local (when configured inansible.cfg)
Need a system-wide install? Add sudo:
sudo ansible-galaxy collection install community.general
Fix 5: Check for Typos in the Module Name
No collection install will help if the module name itself is misspelled. Double-check the exact name:
# Search for modules matching a keyword
ansible-doc -l | grep -i postgres
# View full docs for a specific module
ansible-doc community.postgresql.postgresql_db
Verify the Fix
Before running the playbook for real, do a syntax check first:
ansible-playbook playbook.yml --syntax-check
Clean output looks like this:
playbook: playbook.yml
No errors. Then run a dry run to catch anything else:
ansible-playbook playbook.yml --check
Confirm the collection installed correctly:
ansible-galaxy collection list | grep community.general
# community.general 9.1.0
Prevention
- Use FQCN in every playbook โ it's explicit and survives Ansible upgrades without breaking
- Keep a
requirements.ymlin every Ansible project and commit it to version control - Pin collection versions in
requirements.ymlโ silent breakage on upgrades is easy to avoid this way - In CI/CD, run
ansible-galaxy collection install -r requirements.ymlbefore any playbook execution - Upgrading past the 2.9 โ 2.10 boundary? Audit your playbooks for modules that moved to collections

