win_xml module 'cannot call a method on a null-valued expression'

391 views
Skip to first unread message

Dave York

unread,
Mar 31, 2020, 6:15:35 PM3/31/20
to Ansible Project
I have an JBoss domain.xml file im trying to manipulate with win_xml:

<domain>
...
   
<server-groups>
       
<server-group name="sandbox" profile="full-ha">
           
<jvm name="default">
               
<heap size="8192m" max-size="8192m"/>
               
<permgen max-size="384m"/>
           
</jvm>
           
<socket-binding-group ref="full-ha-sockets"/>
           
<deployments>
               
<deployment name="XXXXXXXXXXX.ear" runtime-name="XXXXXXXXXXX.ear"/>
           
</deployments>
       
</server-group>
   
</server-groups>


</domain>


When I try to modify the heap size attribute above using win_xml with this play:
  - nameTest modifying XML
    win_xml:
      pathe:\jboss-eap-6.4\XXXXXXX\configuration\domain.xml
      xpath'/domain/server-groups/server-group/jvm/heap'
      attribute'size'
      fragment'123m'
      typeattribute


However, I get an exception that looks like its coming from powershell "You cannot call a method on a null-valued expression
"exception": "You cannot call a method on a null-valued expression.\r\nAt line:204 char:5\r\n+     [bool]$add = !$node.HasAttribute($attribute) -Or ($node.$attribut ...\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException\r\n    + FullyQualifiedErrorId : InvokeMethodOnNull\r\n\r\nScriptStackTrace:\r\nat <ScriptBlock>, <No file>: line 204\r\n",

   
"msg": "Unhandled exception while executing module: You cannot call a method on a null-valued expression.",
   
"_ansible_no_log": false,
   
"changed": false

}


Anyone see my problem? I checked the xpath using Notepad++ xml tools plugin and it seems correct.  Scratchin my head

Dave York

unread,
Mar 31, 2020, 7:12:45 PM3/31/20
to Ansible Project
I forgot to add, the domain tag is:

<domain xmlns="urn:jboss:domain:1.8">

not just 

<domain>

if that's relevant.  

Dave York

unread,
Mar 31, 2020, 9:27:04 PM3/31/20
to Ansible Project
I figured this out.  Turned out that my xml was using a different namespace? I had to follow guidance I found on stackoverflow:
https://stackoverflow.com/questions/5239685/xml-namespace-breaking-my-xpath

So my play now looks like this (and works):
  tasks:
  - nameTest modifying XML
    win_xml:
      pathe:\jboss-eap-6.4\XXXXXXXXX\configuration\domain.xml
      xpath'/*[local-name()="domain"]/*[local-name()="server-groups"]/*[local-name()="server-group"]/*[local-name()="jvm"]/*[local-name()="heap"]'

Dick Visser

unread,
Apr 1, 2020, 1:18:35 AM4/1/20
to ansible...@googlegroups.com
Hi

While that does work, it looks like the xpath expression is flattening too much with all those wildcards. 
The correct way would be to provide the actual namespace, this is supported by the module:




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4c0d8605-8923-4346-bb06-e252c1a18142%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Dick Visser

unread,
Apr 1, 2020, 2:14:03 AM4/1/20
to ansible...@googlegroups.com
Forget what I said - I misread. The win_xml module doesn't have a 'namespaces' option.
I mixed it up with the regular xml module.

--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
Reply all
Reply to author
Forward
0 new messages