请求正文为 int 而不是 string
我正在尝试将注册值(来自 csv)传递到正文中。然而,每当尝试这样做时,它都会返回一个字符串 - 但 API 期望一个 int。即使尝试将其转换为 int 时,它仍然会产生字符串。
- name: Creating vlan
cisco.intersight.intersight_rest_api:
resource_path: /fabric/Vlans
update_method: post
api_body: {
"AutoAllowOnUplinks": true,
"EthNetworkPolicy": "{{ ethpolicies.api_response.Moid }}",
"IsNative": false,
"MulticastPolicy": "{{ multicastpolicies.api_response.Moid }}",
"Name": "{{ item.Name }}",
"VlanId": "{{ item.VLAN | int}}"
}
register: vlancreate
with_items:
- "{{ vlanlist.list }}"
预期结果
"invocation": {
"module_args": {
"api_body": {
"AutoAllowOnUplinks": true,
"EthNetworkPolicy": "...",
"IsNative": false,
"MulticastPolicy": "...",
"Name": "test2",
"VlanId": 100 <- int
实际结果
"invocation": {
"module_args": {
"api_body": {
"AutoAllowOnUplinks": true,
"EthNetworkPolicy": "...",
"IsNative": false,
"MulticastPolicy": "...",
"Name": "test2",
"VlanId": "100" <- string
I'm trying to pass a registered value (from a csv) into a body. However, whenever attempting to do so it want to return a string - but API expect an int. Even when attmpting to convert it to an int, it still results in string.
- name: Creating vlan
cisco.intersight.intersight_rest_api:
resource_path: /fabric/Vlans
update_method: post
api_body: {
"AutoAllowOnUplinks": true,
"EthNetworkPolicy": "{{ ethpolicies.api_response.Moid }}",
"IsNative": false,
"MulticastPolicy": "{{ multicastpolicies.api_response.Moid }}",
"Name": "{{ item.Name }}",
"VlanId": "{{ item.VLAN | int}}"
}
register: vlancreate
with_items:
- "{{ vlanlist.list }}"
Expected result
"invocation": {
"module_args": {
"api_body": {
"AutoAllowOnUplinks": true,
"EthNetworkPolicy": "...",
"IsNative": false,
"MulticastPolicy": "...",
"Name": "test2",
"VlanId": 100 <- int
Actual result
"invocation": {
"module_args": {
"api_body": {
"AutoAllowOnUplinks": true,
"EthNetworkPolicy": "...",
"IsNative": false,
"MulticastPolicy": "...",
"Name": "test2",
"VlanId": "100" <- string
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
动态创建字典,从而避免对字符串进行 Jinja 求值。例如,创建变量api_body_default(下面简化用于测试)并将其与列表中的项目组合。给定列表,
任务
应该按预期进行
Create the dictionary on the fly thus avoiding the Jinja evaluation to strings. For example, create variable api_body_default (below simplified for testing) and combine it with the items from the list. Given the list
the task
should work as expected