【发布时间】:2021-09-28 11:07:46
【问题描述】:
有一个使用 uri module 和 portainer API 的 ansible 任务,正文如下:
ansible.builtin.uri:
body_format: json
headers:
accept: application/json
Content-Type: multipart/form-data
Authorization: "Bearer {{ portainer_auth['json']['jwt'] }}"
body:
Name: "{{ item['Name'] }}"
EndpointCreationType: "{{ item['EndpointCreationType'] }}"
URL: "{{ item['URL'] | default(omit, true) | string }}"
PublicURL: "{{ item['PublicURL'] | default(omit, true) }}"
GroupID: "{{ item['GroupID'] }}"
抛出错误:
"json": "cannot unmarshal string into Go struct field endpointUpdatePayload.GroupID of type int",
"message": "Invalid request payload"
但是这行得通,所以问题似乎出在 ansible 变量中
ansible.builtin.uri:
body_format: json
headers:
accept: application/json
Content-Type: multipart/form-data
Authorization: "Bearer {{ portainer_auth['json']['jwt'] }}"
body:
Name: "{{ item['Name'] }}"
EndpointCreationType: "{{ item['EndpointCreationType'] }}"
URL: "{{ item['URL'] | default(omit, true) | string }}"
PublicURL: "{{ item['PublicURL'] | default(omit, true) }}"
GroupID: 2
当body_format: form-multipart 则错误为
"json": "details": "invalid character '-' in numeric literal",
"message": "Invalid request payload"
有什么想法吗?
【问题讨论】:
-
"{{ item['GroupID'] | int }}"