Open
Description
SUMMARY
ISSUE TYPE
- Bug Report
COMPONENT NAME
client.py
ANSIBLE VERSION
ansible [core 2.16.14]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /bin/ansible
python version = 3.11.10 (main, Sep 24 2024, 09:33:51) [GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] (/usr/bin/python3.11)
jinja version = 3.1.4
libyaml = True
COLLECTION VERSION
# /root/.ansible/collections/ansible_collections
Collection Version
--------------- -------
servicenow.itsm 2.7.0
CONFIGURATION
ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = False
CONFIG_FILE() = /etc/ansible/ansible.cfg
GALAXY_SERVER_LIST(/etc/ansible/ansible.cfg) = ['published_repo', 'rh-certified_repo', 'community_repo']
PAGER(env: PAGER) = less
OS / ENVIRONMENT
Xanadu
STEPS TO REPRODUCE
Host and Access Token is set via Environmental Variable
- name: Create new incident
servicenow.itsm.incident:
caller: "ansible"
state: new
short_description: Demo incident Ansible
impact: low
urgency: low
register: incident
EXPECTED RESULTS
I expect to create an Incident
ACTUAL RESULTS
I received a 401 Error
<localhost> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1737504879.5880816-20852-258024264308178/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/incident.py", line 339, in main
changed, record, diff = run(module, table_client, attachment_client)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/incident.py", line 285, in run
return ensure_present(module, table_client, attachment_client)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/incident.py", line 227, in ensure_present
payload = build_payload(module, table_client)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/modules/incident.py", line 202, in build_payload
user = table.find_user(table_client, module.params["caller"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/table.py", line 63, in find_user
return table_client.get_record("sys_user", dict(user_name=user_id), must_exist=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/table.py", line 28, in get_record
return self.get(self.path(table), query, must_exist)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/snow.py", line 49, in get
records = self.list(api_path, query)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/snow.py", line 28, in list
response = self.client.get(
^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/client.py", line 199, in get
resp = self.request("GET", path, query=query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/client.py", line 196, in request
return self._request(method, url, data=data, headers=headers)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/ansible_servicenow.itsm.incident_payload_15495syh/ansible_servicenow.itsm.incident_payload.zip/ansible_collections/servicenow/itsm/plugins/module_utils/client.py", line 153, in _request
raise AuthError(
fatal: [localhost]: FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/bin/python3.11"
},
"changed": false,
"invocation": {
"module_args": {
"attachments": null,
"caller": "ansible",
"close_code": null,
"close_notes": null,
"description": null,
"hold_reason": null,
"impact": "low",
"incident_mapping": null,
"instance": {
"access_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"api_path": "api/now",
"client_id": null,
"client_secret": null,
"custom_headers": null,
"grant_type": null,
"host": "https://schneidernatlprod.service-now.com",
"password": null,
"refresh_token": null,
"timeout": null,
"username": null,
"validate_certs": true
},
"number": null,
"other": null,
"short_description": "Demo incident Ansible",
"state": "new",
"sys_id": null,
"urgency": "low"
}
},
"msg": "Failed to authenticate with the instance: 401 Unauthorized"
}
WORK AROUND
I modified
to
def _login_access_token(self, access_token):
return dict({"x-sn-apikey": access_token})
Metadata
Assignees
Labels
No labels
Activity