Skip to content

Latest commit

 

History

History
547 lines (488 loc) · 24.7 KB

servicenow.itsm.api_module.rst

File metadata and controls

547 lines (488 loc) · 24.7 KB

servicenow.itsm.api module -- Manage ServiceNow POST, PATCH and DELETE requests

This module is part of the servicenow.itsm collection (version 2.7.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install servicenow.itsm.

To use it in a playbook, specify: servicenow.itsm.api.

New in servicenow.itsm 2.0.0

This module has a corresponding action plugin.

Parameter

Comments

action

string / required

The action to perform.

Choices:

  • "post"

  • "patch"

  • "delete"

api_path

string

added in servicenow.itsm 2.5.0

The path of the service which a record is to be created, updated or deleted from.

Mutually exclusive with resource.

Require one of resource or api_path.

data

dictionary

The data that we want to update or create the resource with.

Mutually exclusive with template.

Only relevant if action==patch or action==post.

A Dict consists of resource's column names as keys (such as description, number, priority, and so on) and the patching values as values (the value we want to change the column to).

When updating a resource's record, if no datum is specified for a specific column, the value of that column will remain intact.

When creating a resource's record, if no datum is specified for a specific column, the default value of the column will be used.

Default: {}

instance

dictionary

ServiceNow instance information.

access_token

string

added in servicenow.itsm 2.3.0

Access token obtained via OAuth authentication.

If not set, the value of the SN_ACCESS_TOKEN environment variable will be used.

api_path

string

added in servicenow.itsm 2.4.0

Change the API endpoint of SNOW instance from default 'api/now'.

Default: "api/now"

client_id

string

ID of the client application used for OAuth authentication.

If not set, the value of the SN_CLIENT_ID environment variable will be used.

If provided, it requires client_secret.

client_secret

string

Secret associated with client_id. Used for OAuth authentication.

If not set, the value of the SN_CLIENT_SECRET environment variable will be used.

If provided, it requires client_id.

custom_headers

dictionary

added in servicenow.itsm 2.4.0

A dictionary containing any extra headers which will be passed with the request.

grant_type

string

added in servicenow.itsm 1.1.0

Grant type used for OAuth authentication.

If not set, the value of the SN_GRANT_TYPE environment variable will be used.

Since version 2.3.0, it no longer has a default value in the argument specifications.

If not set by any means, the default value (that is, password) will be set internally to preserve backwards compatibility.

Choices:

  • "password"

  • "refresh_token"

host

string / required

The ServiceNow host name.

If not set, the value of the SN_HOST environment variable will be used.

password

string

Password used for authentication.

If not set, the value of the SN_PASSWORD environment variable will be used.

Required when using basic authentication or when grant_type=password.

refresh_token

string

added in servicenow.itsm 1.1.0

Refresh token used for OAuth authentication.

If not set, the value of the SN_REFRESH_TOKEN environment variable will be used.

Required when grant_type=refresh_token.

timeout

float

Timeout in seconds for the connection with the ServiceNow instance.

If not set, the value of the SN_TIMEOUT environment variable will be used.

username

string

Username used for authentication.

If not set, the value of the SN_USERNAME environment variable will be used.

Required when using basic authentication or when grant_type=password.

validate_certs

boolean

added in servicenow.itsm 2.3.0

If host's certificate is validated or not.

Choices:

  • false

  • true ← (default)

query_params

dictionary

added in servicenow.itsm 2.1.0

Query parameters that may be used on POST or PATCH request.

Default: {}

resource

string

The name of the table in which a record is to be created, updated or deleted from.

Mutually exclusive with api_path.

Require one of resource or api_path

sys_id

string

Required if action==patch or action==delete.

template

string

Provide a valid YAML template definition file for creating or updating a record.

Provides built-in template processing capabilities as an alternative to its data parameter.

Mutually exclusive with data.

If template starts with "/", it is assumed you have specified absolute path to the file. Otherwise, it is assumed you have specified relative path to the file.

Template file needs to be present on the Ansible Controller's system. Otherwise, an error is raised.

- name: Create a record in table incident with specified short_description (which is read from data)
  servicenow.itsm.api:
    resource: incident
    action: post
    data:
      short_description: my-incident
  register: result

- name: Create a record in table incident with column values set in template, located in Ansible controller file system
  servicenow.itsm.api:
    resource: incident
    action: post
    template: '/testing/deployment.j2'
  register: result

- name: Update a record with given sys_id in table incident with template, located in Ansible controller file system
  servicenow.itsm.api:
    resource: incident
    action: patch
    sys_id: 46b66a40a9fe198101f243dfbc79033d
    template: '/testing/deployment.j2'
  register: result

- name: Update column short_description (specified in data) in table incident of a record with given sys_id
  servicenow.itsm.api:
    resource: incident
    action: patch
    sys_id: 46b66a40a9fe198101f243dfbc79033d
    data:
      short_description: my-incident-updated
  register: result

- name: Delete the resource the table incident with given sys_id
  servicenow.itsm.api:
    resource: incident
    action: delete
    sys_id: 46b66a40a9fe198101f243dfbc79033d
  register: result

- name: Create a record in the table sc_req_item and set short_description's value to demo-description2
  servicenow.itsm.api:
    resource: sc_req_item
    action: post
    data:
      short_description: demo-description2
  register: result

- name: Create a record in the table sc_req_item and set short_description's value to demo-description2
  servicenow.itsm.api:
    resource: sc_req_item
    action: post
    data:
      short_description: demo-description2
  register: result

- name: create user (object with encrypted fields)
  servicenow.itsm.api:
    resource: sys_user
    action: post
    query_params:
      sysparm_input_display_value: true
    data:
      user_name: "demo_username"
      user_password: "demo_password"
      first_name: "first_name"
      last_name: Demouser
      department: IT
      email: "demo_username@example.com"
      title: Demo user
  register: user

- name: Create a record in sc_req_item with column values set in template, located in Ansible controller file system
  servicenow.itsm.api:
    resource: sc_req_item
    action: post
    template: '/testing/deployment.j2'
  register: result

- name: Delete a record by sys_id from table sc_req_item
  servicenow.itsm.api:
    resource: sc_req_item
    action: delete
    sys_id: b82adae197201110949235dfe153afec
  register: result

- name: Create a record in cmdb service using api_path
  servicenow.itsm.api:
    api_path: api/now/cmdb/instance/cmdb_ci_linux_server
    action: post
    data:
      attributes:
        name: "linux99"
        firewall_status: "intranet"
    source: "ServiceNow"

The following are the fields unique to this module:

Key

Description

record

dictionary

The created, updated or deleted record.

Returned: success

Sample: {"active": "true", "activity_due": "", "additional_assignee_list": "", "approval": "not requested", "approval_history": "", "approval_set": "", "assigned_to": "", "assignment_group": "", "business_duration": "", "business_impact": "", "business_service": "", "business_stc": "", "calendar_duration": "", "calendar_stc": "", "caller_id": "", "category": "inquiry", "cause": "", "caused_by": "", "child_incidents": "0", "close_code": "", "close_notes": "", "closed_at": "", "closed_by": "", "cmdb_ci": "", "comments": "", "comments_and_work_notes": "", "company": "", "contact_type": "", "contract": "", "correlation_display": "", "correlation_id": "", "delivery_plan": "", "delivery_task": "", "description": "", "due_date": "", "escalation": "0", "expected_start": "", "follow_up": "", "group_list": "", "hold_reason": "", "impact": "3", "incident_state": "1", "knowledge": "false", "location": "", "made_sla": "true", "notify": "1", "number": "INC0010204", "opened_at": "2022-07-06 08:53:05", "opened_by": "6816f79cc0a8016401c5a33be04be441", "order": "", "origin_id": "", "origin_table": "", "parent": "", "parent_incident": "", "priority": "5", "problem_id": "", "reassignment_count": "0", "reopen_count": "0", "reopened_by": "", "reopened_time": "", "resolved_at": "", "resolved_by": "", "rfc": "", "route_reason": "", "service_offering": "", "severity": "3", "short_description": "my-incident", "sla_due": "", "state": "1", "subcategory": "", "sys_class_name": "incident", "sys_created_by": "admin", "sys_created_on": "2022-07-06 08:53:05", "sys_domain": "global", "sys_domain_path": "/", "sys_id": "35b5fb4197245110949235dfe153af06", "sys_mod_count": "0", "sys_tags": "", "sys_updated_by": "admin", "sys_updated_on": "2022-07-06 08:53:05", "task_effective_number": "INC0010204", "time_worked": "", "universal_request": "", "upon_approval": "proceed", "upon_reject": "cancel", "urgency": "3", "user_input": "", "watch_list": "", "work_end": "", "work_notes": "", "work_notes_list": "", "work_start": ""}

Authors

  • Tjaž Eržen (@tjazsch)
  • Jure Medvešek (@juremedvesek)

Collection links