ansible-collections / community.windows

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

win_xml "SchemaInfo not found" exception when adding a element to a root element #238

Open stf1981 opened 3 years ago

stf1981 commented 3 years ago
SUMMARY

I try to add a element under the root element, than it comes to a exception. See Below. When i run the same code piece from the ps1 module directly on the remote machine, than the "SchemaInfo" property is available. I don´t know what is going on.

ISSUE TYPE
COMPONENT NAME

win_xml

ANSIBLE VERSION
ansible 2.10.9
  config file = /mnt/c/work_git/oxygen/Station/Deployment/Ansible/ansible.cfg
  configured module search path = [u'/home/stefan/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/stefan/.local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.17 (default, Sep 30 2020, 13:38:04) [GCC 7.5.0]
CONFIGURATION
DEFAULT_FORKS(/mnt/c/work_git/oxygen/Station/Deployment/Ansible/ansible.cfg) = 50
DEFAULT_HOST_LIST(/mnt/c/work_git/oxygen/Station/Deployment/Ansible/ansible.cfg) = [u'/mnt/c/work_git/oxygen/Station/Deployment/Ansible/hosts.yml']
DEFAULT_LOG_PATH(/mnt/c/work_git/oxygen/Station/Deployment/Ansible/ansible.cfg) = /mnt/c/work_git/oxygen/Station/Deployment/Ansible/deployment.log
DEFAULT_ROLES_PATH(/mnt/c/work_git/oxygen/Station/Deployment/Ansible/ansible.cfg) = [u'/mnt/c/work_git/oxygen/Station/Deployment/Ansible/oxygen_win/roles']
OS / ENVIRONMENT

Target OS: Windows 10 Community.Windows: 1.3.0

STEPS TO REPRODUCE

I have the following XML

<?xml version="1.0" encoding="utf-8"?>
<IndexServerList>
</IndexServerList>

Tan i try to add one element under the root element with

    win_xml:
     path: '{{oxygenDir}}\Updater\IndexServerList.xml'
     xpath: '//IndexServerList'
     fragment: '<Host Uri="{{indexServerUri}}" />'
EXPECTED RESULTS

The "Host" element ist added under the "IndexServerList" root element.

ACTUAL RESULTS
The full traceback is:
Die Eigenschaft "SchemaInfo" wurde für dieses Objekt nicht gefunden. Vergewissern Sie sich, dass die Eigenschaft vorhanden ist.
In Zeile:135 Zeichen:1
+ $namespaceMgr.AddNamespace($xmlorig.$localname.SchemaInfo.Prefix, $na ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

ScriptStackTrace:
bei <ScriptBlock>, <Keine Datei>: Zeile 135
fatal: [192.168.0.123]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: Die Eigenschaft \"SchemaInfo\" wurde für dieses Objekt nicht gefunden. Vergewissern Sie sich, dass die Eigenschaft vorhanden ist."
}
Khyalis commented 2 years ago

I ran into the same issue.

Apparently, if the root element is not empty, it the code in win_xml.ps1 can access it using $xmlOrig.$localname (with $localname being the local name of the root element).

Maybe changing the code to directly access $xmlOrig.DocumentElement might achieve the same thing, but also when the root element is empty. (I lack the insight as to for what reasons the access is implemented the way it is.)