'ERROR! couldn't resolve module/action . This often indicates a misspelling, missing collection, or incorrect module path

I've got an Ansible Collections in my Ansible playbook as follows:

- name: Create a profile for the user
  community.windows.win_user_profile:
    username: test
    name: test
    state: present

and the collection is installed via

ansible-galaxy collection install ansible.windows

so I can see it at ~/.ansible/collections.

However I keep getting:

ERROR! couldn't resolve module/action 'community.windows.win_user_profile'. This often indicates a misspelling, missing collection, or incorrect module path.

I've also copied it alongside the playbook just in case but still get the same error message.

Any suggestions?



Solution 1:[1]

Adding below details to your question would be helpful

  1. Ansible host operating system
  2. Ansible version

I guess, this is error is specific to ansible version. I guess you are using ansible 2.9 version or lower version. whereas, Installing collections with ansible-galaxy is only supported in ansible 2.9+.

Reference link : https://galaxy.ansible.com/ansible/windows ( look into 'Note' section )

You can upgrade your ansible version and give a try.

Reference link : https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#upgrading-from-2-9-or-earlier-to-2-10

Solution 2:[2]

There are two Windows collections: community and Supported. I know that's confusing :(

Looks like you've installed ansible.windows, though you are using community.windows

The fix is:

ansible-galaxy collection install community.windows

Solution 3:[3]

ansible 2.9 uses collections different. One way is to add them to the top:

---
- hosts: all
  collections:
    - community.windows

and then later use:

- name: Create a profile for the user
  win_user_profile:
    username: test
    name: test
    state: present

for reference:

Dirty: dont do this, but it works.

ansible-config dump |grep DEFAULT_MODULE_PATH

and copy them there (example replace path and name)...

cp -p  ~/.ansible/collections/ansible_collections/community/general/plugins/modules/system/sudoers.py ./library/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tapan Hegde
Solution 2 Gundalow
Solution 3