Hello. The problem is this: I can attach a file to a Change request manually, but not via an Ansible automation playbook.
I am using the Ansible ServiceNow ITSM. Essentially, it is a Python-based automation software that extends the capabilities of ServiceNow. The playbook I am using is supposed to do Oracle GoldenGate work (which works fine), then it is suppose to close the auto-opened and executed Change Request that triggered the work and attach the work log to the CR.
Here is the task that fails within the automation:
- name: Close the CR Oracle GoldenGate replicat down, out of sync Process ID 2872.56 {{ change_task_ogg_resync_change_request_number }} after a successful execution on {{ ansible_date_time.iso8601 }}
servicenow.itsm.change_request:
instance:
host: "{{ sn_instance}}"
username: "{{ sn_username }}"
password: "{{ sn_password }}"
state: closed
assignment_group: Database Atlanta
close_code: successful
close_notes: Hyperautomation has successfully closed CR at "{{ ansible_date_time.iso8601 }}"
attachments:
- path: /tmp/ansible.log
number: "{{ change_task_ogg_resync_change_request_number }}"
The playbook above runs fine only if I comment out the two “attachments” lines. Also, I can attach the same file in the Web GUI as the same user. But the point of the automation is to be able to do this unattended.
Here is the error:
TASK [Close the CR Oracle GoldenGate replicat down, out of sync Process ID 2872.56 CR CHG0030553 after a successful execution on 2025-12-13T15:12:26Z] ***********************************************************************************************************************************************
task path: /etc/ansible/playbooks/close_ogg_resync_cr.yml:22
The full traceback is:
Traceback (most recent call last):
File "<stdin>", line 102, in <module>
File "<stdin>", line 94, in _ansiballz_main
File "<stdin>", line 40, in invoke_module
File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/change_request.py", line 475, in <module>
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/change_request.py", line 468, in main
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/change_request.py", line 377, in run
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/change_request.py", line 333, in ensure_present
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/attachment.py", line 102, in update_records
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/attachment.py", line 70, in upload_record
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/attachment.py", line 56, in create_record
KeyError: 'result'
fatal: [localhost]: FAILED! => changed=false
module_stderr: |-
Traceback (most recent call last):
File "<stdin>", line 102, in <module>
File "<stdin>", line 94, in _ansiballz_main
File "<stdin>", line 40, in invoke_module
File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/change_request.py", line 475, in <module>
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/change_request.py", line 468, in main
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/change_request.py", line 377, in run
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/change_request.py", line 333, in ensure_present
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/attachment.py", line 102, in update_records
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/attachment.py", line 70, in upload_record
File "/tmp/ansible_servicenow.itsm.change_request_payload_q_4egali/ansible_servicenow.itsm.change_request_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/attachment.py", line 56, in create_record
KeyError: 'result'
module_stdout: ''
msg: |-
MODULE FAILURE
See stdout/stderr for the exact error
rc: 1
PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
192.168.1.202 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
localhost : ok=21 changed=11 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Here is the link to the ServiceNow Ansible ITSM module documentation with the correct “attachment” syntax:

