现在使用Ansible将CSV附加到服务记录

时间:2019-03-15 15:19:35

标签: rest api ansible servicenow

- name: Attach CSV to record
    uri:
        url: "https://devvvvv.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id={{ sysid }}&file_name=ticketCSV.csv"
        method: POST
        user: "{{ sn_username }}"
        password:  "{{ sn_password }}"
        force_basic_auth: yes
        headers:
            Content-Type: "application/json"
            Accept: "application/json"
        return_content: yes

这是ansible的新功能,但是想知道如何将CSV附加到该记录中,我认为大多数情况下是正确的,但是不知道如何设置文件的路径。在文档中,它讨论了位置的响应标头,该放在哪里? 此处是链接https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/integrate/inbound_rest/reference/r_AttachmentAPI-POSTmultipart.html

2 个答案:

答案 0 :(得分:0)

“响应标头”是您上传文件后从SNOW获得的响应。然后,SNOW会告诉您上载文件的URL。

要通过ansible上传文件,可以查看其文档,尤其是“ src”标签:https://docs.ansible.com/ansible/latest/modules/uri_module.html

答案 1 :(得分:0)

我能够做到这一点 在下面找到我使用的代码

 - name: Attach evidence to change record
   uri:
    url: "{{ snow_api }}/now/attachment/file?table_name=change_request&table_sys_id={{ change_created.json.result.sys_id }}&file_name=patches_on_test.txt"
    method: POST
    headers:
      Content-Type: "application/json"
      Accept: "application/json,version=2"
      Authorization: "Basic {{ credential }}"
    body: "{{ yum_history_info.stdout }}"
    force_basic_auth: yes
    body_format: json
    validate_certs: no
    timeout: 120
    status_code: 200,202,201
   failed_when: false
   register: doc_upload
   delegate_to: 127.0.0.1