Would love to see some practical examples of syntax use when using the iControl REST API.
I’m trying to modify a datagroup data value via the API, but failing. Using Postman, successfully auth’d, sending PATCH https://dev-lb1.lab.int/mgmt/tm/ltm/dataGroup/internal/~Common~mtest-routing-datagroup{“records”:[“name”:“default”, “data”:“virt_host2”]}
Test is to modify the data value, from “virt_host1” to “virt_host2” Then take this and turn it into an ansible task.
The syntax surrounding defining what I’m changing is unclear, and so far I’ve only managed to test exceptions
In other words, what I’m looking for is the correct syntax for this part:
{“records”:[“name”:“default”, “data”:“virt_host2”]}
I’ve tried as just a normal key, value pair, but it doesn’t like that either… So when passing a PATCH back to the F5, how should these variables be presented?
I believe you are missing curly brackets around the name/value object. i.e.,
{"records":[ {"name":"default", "data":"virt_host2"} ]}
Example:
curl -sku admin: https:///mgmt/tm/ltm/data-group/internal/images
{ kind: 'tm:ltm:data-group:internal:internalstate',
name: 'images',
fullPath: 'images',
generation: 299,
selfLink: 'https://localhost/mgmt/tm/ltm/data-group/internal/images?ver=11.6.1',
type: 'string',
records: [ { name: 'ext1', data: '.ppm' } ]
}
curl -sku admin: https:///mgmt/tm/ltm/data-group/internal/images \
-X PATCH -H "Content-type: application/json" \
-d '{"records":[ {"name": "ext1", "data":".png"} ]}'
{ kind: 'tm:ltm:data-group:internal:internalstate',
name: 'images',
fullPath: 'images',
generation: 306,
selfLink: 'https://localhost/mgmt/tm/ltm/data-group/internal/images?ver=11.6.1',
type: 'string',
records: [ { name: 'ext1', data: '.png' } ]
}
Updating this in case anyone else gets stuck fetching & changing datagroups with ansible. Playbook snippet comparing datagroup values and changing when necessary:
- name: get data via REST api
uri:
url: "https://{{ inventory_hostname }}/mgmt/tm/ltm/dataGroup/internal/~Common~mtest-routing-datagroup"
method: GET
force_basic_auth: yes
user: "{{ f5_admin_user }}"
password: "{{ f5_admin_password }}"
validate_certs: no
register: result
tags:
- always
- name: save current datagroup info
set_fact:
current_data="{{ result.json['records'][0]['data'] }}"
tags:
- always
- name: Change data
uri:
url: "https://{{ inventory_hostname }}/mgmt/tm/ltm/dataGroup/internal/~Common~mtest-routing-datagroup"
method: PATCH
force_basic_auth: yes
user: "{{ f5_admin_user }}"
password: "{{ f5_admin_password }}"
validate_certs: no
body: {"records":[ {"name": "default", "data":"{{ desired_data }}"} ]}
body_format: json
status_code: 200
when: not current_data == desired_data
changed_when: not current_data == desired_data
tags:
- always