ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
198 stars 153 forks source link

`community.windows.win_credential` fails with "Failed to access the user's credential store, run the module with become" #497

Closed nemonik closed 1 year ago

nemonik commented 1 year ago
SUMMARY
- name: Create credential
  community.windows.win_credential:
    name: 127.0.0.1
    type: generic_password
    username: Administrator
    secret: "Ch@ng3M3!"
    state: present

Results in

The full traceback is:
Exception calling "GetCredential" with "2" argument(s): "Failed to access the user's credential store, run the module with become"
At line:578 char:1
+ $existing_credential = [Ansible.CredentialManager.Credential]::GetCre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidOperationException

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 578
fatal: [IP]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: Exception calling \"GetCredential\" with \"2\" argument(s): \"Failed to access the user's credential store, run the module with become\""
}
ISSUE TYPE
COMPONENT NAME

community.windows.win_credential

ANSIBLE VERSION
➜  ansible --version
ansible [core 2.13.5]
  config file = None
  configured module search path = ['/home/nemonik.linux/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/nemonik.linux/.cache/pypoetry/virtualenvs/something-rnn__9Px-py3.10/lib/python3.10/site-packages/ansible
  ansible collection location = /home/nemonik.linux/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/nemonik.linux/.cache/pypoetry/virtualenvs/something-rnn__9Px-py3.10/bin/ansible
  python version = 3.10.7 (main, Jan  5 2023, 00:11:54) [GCC 11.3.0]
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /home/nemonik.linux/.cache/pypoetry/virtualenvs/something-rnn__9Px-py3.10/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.windows 1.11.0

# /home/nemonik.linux/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.windows 1.12.0
CONFIGURATION
returned nothing
OS / ENVIRONMENT
Linux lima-mep 5.15.0-67-generic #74-Ubuntu SMP Wed Feb 22 14:14:39 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
STEPS TO REPRODUCE
- name: Create credential
  community.windows.win_credential:
    name: 127.0.0.1
    type: generic_password
    username: Administrator
    secret: "Ch@ng3M3!"
    state: present
EXPECTED RESULTS

To create the credential

ACTUAL RESULTS
The full traceback is:
Exception calling "GetCredential" with "2" argument(s): "Failed to access the user's credential store, run the module with become"
At line:578 char:1
+ $existing_credential = [Ansible.CredentialManager.Credential]::GetCre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidOperationException

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 578
fatal: [IP]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: Exception calling \"GetCredential\" with \"2\" argument(s): \"Failed to access the user's credential store, run the module with become\""

But

cmdkey /generic:127.0.0.1 /user:"Administrator" /pass:"Ch@ngeM3!" 

works.

jborean93 commented 1 year ago

Did you run it with become (and a password)? Running something locally is different from running it through Ansible. You need to use become to ensure the credential store can be unlocked hence why the error indicates you need to use become.

jborean93 commented 1 year ago

Closing due to no response from the above.