Hello Ansible Community,
I'm currently facing an issue while trying to execute a Spectrum API call using the Ansible URI module. The API call is working fine in Postman, but when I try to replicate it in Ansible, I encounter problems.
Here's a simplified version of my Ansible playbook:
---
- hosts: your_target_hosts
tasks:
- name: Execute Spectrum API
uri:
url: "http://{{ spectrum_server }}/spectrum/restful/models"
method: POST
headers:
Content-Type: "application/xml"
body_format: raw
body: |
<rs:model-request throttlesize="5"
xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">
<rs:target-models>
<rs:models-search>
<rs:search-criteria
xmlns="http://www.ca.com/spectrum/restful/schema/filter">
<devices-only-search/>
<filtered-models>
<equals>
<attribute id="0x1006e">
<value>YourActualDeviceName</value>
</attribute>
</equals>
</filtered-models>
</rs:search-criteria>
</rs:models-search>
</rs:target-models>
<rs:requested-attribute id="0x1006e" />
<rs:requested-attribute id="0x129fa" />
</rs:model-request>
register: response
- name: Print API Response
debug:
var: response
Hello Ansible Community,
I'm currently facing an issue while trying to execute a Spectrum API call using the Ansible URI module. The API call is working fine in Postman, but when I try to replicate it in Ansible, I encounter problems.
I have two APIs related to CA Spectrum. The first API puts network devices in maintenance mode, and the second API is used to find the model MH value based on a device name.
API Details:
1. Maintenance Mode API:
URL: `http://CAserver:portnumber/spectrum/restful/model/0xa0000fa0?attr=0x1295d&val=false`
Issue: I need to find the correct value (e.g., `0xa0000fa0`) to replace in the URL.
2. Find Model API:
URL: `http://CAserver:portnumber/spectrum/restful/models/`
Body:
<rs:model-request throttlesize="5"
xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">
<rs:target-models>
<rs:models-search>
<rs:search-criteria
xmlns="http://www.ca.com/spectrum/restful/schema/filter">
<devices-only-search/>
<filtered-models>
<equals>
<attribute id="0x1006e">
<value>YourActualDeviceName</value>
</attribute>
</equals>
</filtered-models>
</rs:search-criteria>
</rs:models-search>
</rs:target-models>
<rs:requested-attribute id="0x1006e" />
<rs:requested-attribute id="0x129fa" />
</rs:model-request>
Issue: I've received an XML response, and I need to extract the 'mh' value from it to use in the Maintenance Mode API.
XML Response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model-response-list xmlns=http://www.ca.com/spectrum/restful/schema/response total-models="156" throttle="156" error="EndOfResults">
<model-responses>
<model mh="0x19206c00">
<attribute id="0x19206e">192.168.74.63</attribute>
<attribute id="0x12d7f">192.168.74.63</attribute>
</model>
</model-responses>
</model-responses-list>
Request for Help:
1. How can I extract the 'mh' value from the XML response using Ansible?
2. Once I have the 'mh' value, how can I dynamically replace it in the Maintenance Mode API URL?