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

win_pssession_configuration: Fix parser error + add diff mode support #491

Closed tortenairbag closed 1 year ago

tortenairbag commented 1 year ago
SUMMARY

win_pssession_configuration throws errors if changes are applies to a PS Session Configuration that contains JEA features. It's a plugin result parsing error due to some outputs that are not piped into the void (aka null), looking like this:

failed to parse module output: Invalid JSON primitive: icrosoft.WSMan.Management.WSManConfigContainerElement.

Diff mode support was added for this plugin too. It only works for changes and does not contain any info if the session is not created yet.

ISSUE TYPE
COMPONENT NAME

win_pssession_configuration

ADDITIONAL INFORMATION

Playbook:

- name: "Create a configuration with JEA features"
  win_pssession_configuration:
    name: "{{ config_name }}"
    description: "{{ config_description }}"
    modules_to_import: Microsoft.PowerShell.Utility
    visible_aliases: []
    visible_cmdlets: []
    visible_external_commands: []
    visible_functions: []
    security_descriptor_sddl: "O:NSG:BAD:P(A;;GA;;;IU)(A;;GA;;;BA)(A;;GA;;;RM)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)"
  register: status

- name: "Update configuration, use same parameters as above"
  win_pssession_configuration:
    name: "{{ config_name }}"
    description: "{{ config_description }}"
    modules_to_import: Microsoft.PowerShell.Utility
    visible_aliases: []
    visible_cmdlets: []
    visible_external_commands: []
    visible_functions: []
    security_descriptor_sddl: "O:NSG:BAD:P(A;;GA;;;IU)(A;;GA;;;BA)(A;;GA;;;RM)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)"
  register: status

Output:

TASK [Create a configuration with JEA features] *************************************************************************************************************
changed

TASK [Update configuration, use same parameters as above] ***************************************************************************************************
FAILED! => {"msg": "failed to parse module output: Invalid JSON primitive: icrosoft.WSMan.Management.WSManConfigContainerElement."}

WINRM RESULT '<Response code 0, out "{"ansible_async_watc", err "#< CLIXML\r\n<Objs Ver">'
Async Job Status: {'ansible_async_watchdog_pid': 123, 'stdout': '{"changed":true,"invocation":{...}}\r\n\r\nMicrosoft.WSMan.Management.WSManConfigContainerElement\r\n', 'finished': 1, 'stderr': '', 'started': 1, 'failed': True, 'msg': 'failed to parse module output: Invalid JSON primitive: icrosoft.WSMan.Management.WSManConfigContainerElement.', 'changed': False, '_ansible_parsed': True, 'stdout_lines': ['{"changed":true,"invocation":{...}}', '', 'Microsoft.WSMan.Management.WSManConfigContainerElement'], 'stderr_lines': []} 
github-actions[bot] commented 1 year ago

This pull request is stale because it has been open for 4 weeks with no activity. Remove stale label or comment or this will be closed in 2 weeks.