n3pjk.servicenow.snow_record_find (0.0.26) — module

Search for multiple records from ServiceNow

Authors: Tim Rightnour (@garbled1)

Install collection

Install with ansible-galaxy collection install n3pjk.servicenow:==0.0.26


Add to requirements.yml

  collections:
    - name: n3pjk.servicenow
      version: 0.0.26

Description

Gets multiple records from a specified table from ServiceNow based on a query dictionary.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Search for incident assigned to group, return specific fields
  servicenow.servicenow.snow_record_find:
    username: ansible_test
    password: my_password
    instance: dev99999
    table: incident
    query:
      assignment_group: d625dccec0a8016700a222a0f7900d06
    return_fields:
      - number
      - opened_at
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Search for incident using host instead of instance
  servicenow.servicenow.snow_record_find:
    username: ansible_test
    password: my_password
    host: dev99999.mycustom.domain.com
    table: incident
    query:
      assignment_group: d625dccec0a8016700a222a0f7900d06
    return_fields:
      - number
      - opened_at
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Using OAuth, search for incident assigned to group, return specific fields
  servicenow.servicenow.snow_record_find:
    username: ansible_test
    password: my_password
    client_id: "1234567890abcdef1234567890abcdef"
    client_secret: "Password1!"
    instance: dev99999
    table: incident
    query:
      assignment_group: d625dccec0a8016700a222a0f7900d06
    return_fields:
      - number
      - opened_at
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Find open standard changes with my template
  servicenow.servicenow.snow_record_find:
    username: ansible_test
    password: my_password
    instance: dev99999
    table: change_request
    query:
      AND:
        equals:
          active: "True"
          type: "standard"
          u_change_stage: "80"
        contains:
          u_template: "MY-Template"
    return_fields:
      - sys_id
      - number
      - sys_created_on
      - sys_updated_on
      - u_template
      - active
      - type
      - u_change_stage
      - sys_created_by
      - description
      - short_description

Inputs

    
auth:
    choices:
    - basic
    - oauth
    - token
    - okta
    default: basic
    description:
    - The method used to authenticate with the Service Now instance.
    - Basic authentication uses user name and password.
    - OAuth authentication uses a client id and secret in addition to basic authentication.
    - Token authentication uses an externally obtained bearer token, in addition to OAuth
      authentication.
    - Okta authentication is a specific method of obtaining a bearer token.
    - If the vaule is not specified in the task, the value of environment variable C(SN_AUTH)
      will be used instead.
    type: str

host:
    description:
    - The ServiceNow hostname.
    - This value is FQDN for ServiceNow host.
    - If the value is not specified in the task, the value of environment variable C(SN_HOST)
      will be used instead.
    - Mutually exclusive with C(instance).
    type: str

query:
    description:
    - Dict to query for records.
    required: true
    type: dict

table:
    default: incident
    description:
    - Table to query for records.
    required: false
    type: str

token:
    description:
    - Bearer token associated with client id and secret.
    - Can be used in place of client id and secret for OpenID authentication.
    required: false
    type: str

instance:
    description:
    - The ServiceNow instance name, without the domain, service-now.com.
    - If the value is not specified in the task, the value of environment variable C(SN_INSTANCE)
      will be used instead.
    required: false
    type: str

order_by:
    default: -created_on
    description:
    - Field to sort the results on.
    - Can prefix with "-" or "+" to change descending or ascending sort order.
    required: false
    type: str

password:
    description:
    - Password for username.
    - Required whether using Basic, OAuth or OpenID authentication.
    - If the value is not specified in the task, the value of environment variable C(SN_PASSWORD)
      will be used instead.
    required: false
    type: str

username:
    description:
    - Name of user for connection to ServiceNow.
    - Required whether using Basic, OAuth or OpenID authentication.
    - If the value is not specified in the task, the value of environment variable C(SN_USERNAME)
      will be used instead.
    required: false
    type: str

client_id:
    description:
    - Client ID generated by ServiceNow.
    - Required when using OAuth or OpenID authentication, unless token is specified.
    required: false
    type: str

max_records:
    default: 20
    description:
    - Maximum number of records to return.
    required: false
    type: int

client_secret:
    description:
    - Client Secret associated with client id.
    - Required when using OAuth or OpenID authentication, unless token is specified.
    required: false
    type: str

return_fields:
    description:
    - Fields of the record to return in the json.
    - By default, all fields will be returned.
    elements: str
    required: false
    type: list

Outputs

record:
  description: The full contents of the matching ServiceNow records as a list of records.
  returned: always
  type: dict