�
�Udac @` s� d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d
Z d d l
Z
d d l m Z d d
l
m Z m Z d d l m Z y d d l Z Wn e k
r� n Xd � Z d � Z e d k r� e � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bysG
---
module: snow_record
short_description: Manage records in ServiceNow
version_added: "2.5"
description:
- Creates, deletes and updates a single record in ServiceNow.
options:
table:
description:
- Table to query for records.
required: false
default: incident
type: str
state:
description:
- If C(present) is supplied with a C(number) argument, the module will attempt to update the record with the supplied data.
- If no such record exists, a new one will be created.
- C(absent) will delete a record.
choices: [ present, absent ]
required: true
type: str
data:
description:
- key, value pairs of data to load into the record. See Examples.
- Required for C(state:present).
type: dict
number:
description:
- Record number to update.
- Required for C(state:absent).
required: false
type: str
lookup_field:
description:
- Changes the field that C(number) uses to find records.
required: false
default: number
type: str
attachment:
description:
- Attach a file to the record.
required: false
type: str
requirements:
- python pysnow (pysnow)
author:
- Tim Rightnour (@garbled1)
extends_documentation_fragment: service_now.documentation
sm
- name: Grab a user record
snow_record:
username: ansible_test
password: my_password
instance: dev99999
state: present
number: 62826bf03710200044e0bfc8bcbe5df1
table: sys_user
lookup_field: sys_id
- name: Grab a user record using OAuth
snow_record:
username: ansible_test
password: my_password
client_id: "1234567890abcdef1234567890abcdef"
client_secret: "Password1!"
instance: dev99999
state: present
number: 62826bf03710200044e0bfc8bcbe5df1
table: sys_user
lookup_field: sys_id
- name: Create an incident
snow_record:
username: ansible_test
password: my_password
instance: dev99999
state: present
data:
short_description: "This is a test incident opened by Ansible"
severity: 3
priority: 2
register: new_incident
- name: Delete the record we just made
snow_record:
username: admin
password: xxxxxxx
instance: dev99999
state: absent
number: "{{new_incident['record']['number']}}"
- name: Delete a non-existant record
snow_record:
username: ansible_test
password: my_password
instance: dev99999
state: absent
number: 9872354
failed_when: false
- name: Update an incident
snow_record:
username: ansible_test
password: my_password
instance: dev99999
state: present
number: INC0000055
data:
work_notes : "Been working all day on this thing."
- name: Attach a file to an incident
snow_record:
username: ansible_test
password: my_password
instance: dev99999
state: present
number: INC0000055
attachment: README.md
tags: attach
s�
record:
description: Record data from Service Now
type: dict
returned: when supported
attached_file:
description: Details of the file that was attached via C(attachment)
type: dict
returned: when supported
N( t
AnsibleModule( t to_bytest to_native( t ServiceNowClientc C` s� t j � } | j d t d d d t d d � d t d d d
g d d d t � d t d d d t d d � d t d d d t d d
� d t d d d t d d � d t d d d t d d � � d d g g } d d
d g g g } t d | d t d | d | � } t | � } | j � | j } | j
} | d } | d } | d } | d }
| d } | d } t d t d | d | d |
d | � }
| d d k r�| d } t | d d �} t j
j | � s�| j d d j | � � n | |
d <n d } | j r�|
d k r-t | � |
d <t |
d <n�| d
k r�yL | j d | d i |
| 6� } | j � } t d t � |
d <t |
d <Wq�t j j k
r�d |
d <q�t k
r�} | j d d j t | � � |
� q�Xn� yj | j d | d i |
| 6� } | j � } x. | j � D] \ } } | | | <t |
d <qW| |
d <Wnd t j j k
r|d } | j d | |
� n5 t k
r�} | j d d j t | � � |
� n X| j |
� n | d k r�|
d k r�y"