I have a playbook in Ansible that will allow me to identify a specific set of firewalls, and then update them to a higher version of software. However, I need to take the existing output of my API call and find all instances of "currently installed" versions to ensure that it's not already at the latest version, and remove older instances.
Using this sample XML:
<response status="success">
<result>
<sw-updates last-updated-at="2025/10/10 11:11:11">
<msg/>
<versions>
<entry>
<version>6.3.1</version>
<downloaded>no</downloaded>
<current>no</current>
<latest>no</latest>
<uploaded>no</uploaded>
<sha256>7e3505720ecbe981f3ce744b7530844eb2d892f340bcf967b66486112ff11808</sha256>
</entry>
<entry>
<version>6.3.1-c383</version>
<downloaded>no</downloaded>
<current>no</current>
<latest>no</latest>
<uploaded>no</uploaded>
<sha256>8a76ee798630ae3669ffe09f5a1805dd531d3cbc7c29b2e37dc6802223775f87</sha256>
</entry>
<entry>
<version>6.3.0</version>
<downloaded>no</downloaded>
<current>no</current>
<latest>no</latest>
<uploaded>no</uploaded>
<sha256>67a83ff5206d5b4a2aaf13bce3212de270cabe6204a4df1561c35aa4c1bc0f44</sha256>
</entry>
</versions>
</sw-updates>
</result>
</response>
I need to do two things:
- ID all instances where the string
<current>yes</current>occurs, indicating the software is installed and active. - Get the value between
<version></version>for all of those instances.
I can do the first, but its super clunky and relies on me knowing the version number to use a specific XPath. Or using regex, which has its own issues. But I have no idea where to even start for the second. I feel like I am overthinking it, and there is a more simple way to gather the data I need.