Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The term 'Add-Warning' is not recognized #412

Closed
juresaht2 opened this issue Jul 6, 2022 · 2 comments
Closed

The term 'Add-Warning' is not recognized #412

juresaht2 opened this issue Jul 6, 2022 · 2 comments

Comments

@juresaht2
Copy link

Summary

Using module file .ansible/collections/ansible_collections/community/windows/plugins/modules/win_domain_user.ps1
At line:213 char:9
+         Add-Warning -obj $result -message "Failed to enumerate user g ...
+         ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Add-Warning:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException
ScriptStackTrace:
at Get-PrincipalGroup, <No file>: line 213
at <ScriptBlock>, <No file>: line 551

What seems to be happening is that the user info is succesfully obtained, but it fails for some reason to obtain the group information (I did the same steps interactivelly and there was no issue), when it ends up running the catch block it can't parse "Add-Warning".

I couldn't find any Add-Warning in the powershell documentation. There is Write-Warning , but it doesn't have an -obj parameter.

I've tried replacing it with Write-Warning, however this warning does not appear to be displayed anywhere in Ansible, the function simply returns null.

Issue Type

Bug Report

Component Name

lib/ansible/modules/windows/win_domain_user.ps1

Ansible Version

$ ansible --version
ansible 2.9.24
  config file = /var/lib/myframework/.ansible.cfg
  configured module search path = ['/var/lib/myframework/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Mar 19 2021, 05:13:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
HOST_KEY_CHECKING(/var/lib/myframework/.ansible.cfg) = False

OS / Environment

CentOS Linux release 8.4.2105

This is on the Powershell version on the target Windows server:

Name                           Value
----                           -----
PSVersion                      5.1.14409.1027
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1027
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Steps to Reproduce

  community.windows.win_domain_user:
    name: "{{ username }}"
    state: "query"

Expected Results

User information.

Actual Results

TASK [] *********************************************
task path: my/main.yml:2
Using module file .ansible/collections/ansible_collections/community/windows/plugins/modules/win_domain_user.ps1
Pipelining is enabled.
EXEC (via pipeline wrapper)
The full traceback is:
The term 'Add-Warning' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:213 char:9
+         Add-Warning -obj $result -message "Failed to enumerate user g ...
+         ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Add-Warning:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException
ScriptStackTrace:
at Get-PrincipalGroup, <No file>: line 213
at <ScriptBlock>, <No file>: line 551
fatal: [my_server]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: The term 'Add-Warning' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
}


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct
@jborean93
Copy link
Collaborator

The Add-Warning cmdlet is provided by the legacy module wrapper used in older Ansible modules. This module has recently been updated to use the newer wrapper but unfortunately this particular part was missed in the conversion. The PR #416 fixes up this issue so that the warning is properly displayed back to the user to help debug why it's failing to get the group membership.

@endersonmenezes
Copy link

thx =]
Any predictions for a release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants