GithubHelp home page GithubHelp logo

Comments (5)

jborean93 avatar jborean93 commented on July 17, 2024 3

I was finally able to replicate this problem and have a PR which should solve it #244. The issue occurs when there is a mismatch between the UI Culture and the one the PSDesiredStateConfiguration was installed with. Because the psrp connection forces the locale to be en-US you were having a failure where PSDesiredStateConfiguration was trying to load data for en-US when the resources only existed for ja-JP.

What the changes in #244 have done is to temporary change the UI Culture to the installed culture so the import process runs properly before continuing on as normal.

from ansible.windows.

jborean93 avatar jborean93 commented on July 17, 2024

I'm not sure that proposed fix fixes win_dsc, the error here is that the Get-DscResource cmdlet was found in the PSDesiredStateConfiguration module but PowerShell couldn't load it from some reason.

Try running this task to see if it gives you any more errors as to why it couldn't be loaded.

- win_shell: Import-Module PSDesiredStateConfiguration

from ansible.windows.

t-nakajimaa avatar t-nakajimaa commented on July 17, 2024

I tried your idea and it didn't change the win_dsc message.

# diff win_dsc.before.yml win_dsc.yml -u
--- win_dsc.before.yml  2020-07-25 13:00:24.195217100 +0000
+++ win_dsc.yml 2020-07-25 12:53:33.405217100 +0000
@@ -14,6 +14,8 @@
         name: xWebAdministration
         state: present
 
+    - win_shell: Import-Module PSDesiredStateConfiguration
+
     - win_dsc:
         resource_name: xWebsite
         Name: WebApi
# ansible-playbook -i hosts win_dsc.yml -vvvv
ansible-playbook 2.9.10
  config file = /root/.ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]
Using /root/.ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /root/Web/ansible/hosts as it did not pass its verify_file() method
script declined parsing /root/Web/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /root/Web/ansible/hosts as it did not pass its verify_file() method
Parsed /root/Web/ansible/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.8/dist-packages/ansible/plugins/callback/default.py

PLAYBOOK: win_dsc.yml ********************************************************************************************************************************************************************************************
Positional arguments: win_dsc.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/root/Web/ansible/hosts',)
forks: 5
1 plays in win_dsc.yml

PLAY [all] *******************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
task path: /root/Web/ansible/win_dsc.yml:2
Using module file /usr/local/lib/python3.8/dist-packages/ansible/modules/windows/setup.ps1
Pipelining is enabled.
<10.0.4.105> ESTABLISH PSRP CONNECTION FOR USER: Administrator ON PORT 5986 TO 10.0.4.105
PSRP: EXEC (via pipeline wrapper)
ok: [10.0.4.105]
META: ran handlers

TASK [win_shell] *************************************************************************************************************************************************************************************************
task path: /root/Web/ansible/win_dsc.yml:11
Using module file /usr/local/lib/python3.8/dist-packages/ansible/modules/windows/win_shell.ps1
Pipelining is enabled.
<10.0.4.105> ESTABLISH PSRP CONNECTION FOR USER: Administrator ON PORT 5986 TO 10.0.4.105
PSRP: EXEC (via pipeline wrapper)
changed: [10.0.4.105] => {
    "changed": true,
    "cmd": "Install-PackageProvider -Name NuGet",
    "delta": "0:00:03.140734",
    "end": "2020-07-25 01:19:01.644869",
    "rc": 0,
    "start": "2020-07-25 01:18:58.504135",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "",
    "stdout_lines": []
}

TASK [win_psmodule] **********************************************************************************************************************************************************************************************
task path: /root/Web/ansible/win_dsc.yml:13
Using module file /usr/local/lib/python3.8/dist-packages/ansible/modules/windows/win_psmodule.ps1
Pipelining is enabled.
<10.0.4.105> ESTABLISH PSRP CONNECTION FOR USER: Administrator ON PORT 5986 TO 10.0.4.105
PSRP: EXEC (via pipeline wrapper)
ok: [10.0.4.105] => {
    "changed": false,
    "nuget_changed": false,
    "output": "Module xWebAdministration already present",
    "repository_changed": false
}

TASK [win_shell] *************************************************************************************************************************************************************************************************
task path: /root/Web/ansible/win_dsc.yml:17
Using module file /usr/local/lib/python3.8/dist-packages/ansible/modules/windows/win_shell.ps1
Pipelining is enabled.
<10.0.4.105> ESTABLISH PSRP CONNECTION FOR USER: Administrator ON PORT 5986 TO 10.0.4.105
PSRP: EXEC (via pipeline wrapper)
changed: [10.0.4.105] => {
    "changed": true,
    "cmd": "Import-Module PSDesiredStateConfiguration",
    "delta": "0:00:00.859406",
    "end": "2020-07-25 01:19:11.660835",
    "rc": 0,
    "start": "2020-07-25 01:19:10.801429",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "",
    "stdout_lines": []
}

TASK [win_dsc] ***************************************************************************************************************************************************************************************************
task path: /root/Web/ansible/win_dsc.yml:19
Using module file /usr/local/lib/python3.8/dist-packages/ansible/modules/windows/win_dsc.ps1
Pipelining is enabled.
<10.0.4.105> ESTABLISH PSRP CONNECTION FOR USER: Administrator ON PORT 5986 TO 10.0.4.105
PSRP: EXEC (via pipeline wrapper)
The full traceback is:
The 'Get-DscResource' command was found in the module 'PSDesiredStateConfiguration', but the module could not be loaded. For more information, run 'Import-Module PSDesiredStateConfiguration'.
At line:332 char:21
+ $module_versions = (Get-DscResource -Name $resource_name -ErrorAction ...
+                     ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-DscResource:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 332
fatal: [10.0.4.105]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: The 'Get-DscResource' command was found in the module 'PSDesiredStateConfiguration', but the module could not be loaded. For more information, run 'Import-Module PSDesiredStateConfiguration'."
}

PLAY RECAP *******************************************************************************************************************************************************************************************************
10.0.4.105                 : ok=4    changed=2    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

I tried running the command directly in Windows Server, but playbook result is the same.

PS C:\Users\Administrator> Import-Module PSDesiredStateConfiguration
PS C:\Users\Administrator> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...
Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCap...
Manifest   1.1        PSDesiredStateConfiguration         {Invoke-DscResource, Publish-DscConfiguration, Set-DscLoca...
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...

from ansible.windows.

t-nakajimaa avatar t-nakajimaa commented on July 17, 2024

win_template, win_copy and win_service succeed in psrp.

I think this is not a win_dsc problem, although I've only encountered this error with win_dsc at the moment.
In some cases, the psrp response contains non-English messages.
I think psrp.py is not handling it properly.

from ansible.windows.

jborean93 avatar jborean93 commented on July 17, 2024

In some cases, the psrp response contains non-English messages.

That may be the case but the error message you are getting back from win_dsc is

The 'Get-DscResource' command was found in the module 'PSDesiredStateConfiguration', but the module could not be loaded. For more information, run 'Import-Module PSDesiredStateConfiguration'.
At line:332 char:21
+ $module_versions = (Get-DscResource -Name $resource_name -ErrorAction ...
+                     ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-DscResource:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

It's saying that the cmdlet was found but for some reason the PSDesiredStateConfiguration module could not be loaded. The win_shell example I asked you to try shows that Import-Module works so something else is having issues. Can you try the following 2 tasks

- win_shell: |
    Import-Module PSDesiredStateConfiguration -Verbose
    Get-DscResource -Name xWebsite -Verbose

- win_shell: |
    Get-DscResource -Name xWebsite -Verbose

It might also be a good idea to try using raw instead of win_shell for those 2 examples just to imitate the same context that psrp runs a module in.

from ansible.windows.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.