How to create Incident in Service Now using ansible?

Overview

Faster delivery can result in improved support and for stakeholder satisfaction, faster delivery and improved productivity will be the most important thing while automating any service and it is very much satisfied here.

 We can do below operations in Service Now using ansible

         Updating incidents, problems, and change requests

         Updating the Service Now configuration management database (CMDB)

         Using the CMDB as an inventory source  

In this post will demonstrate, how to manage incidents.

First, we need install the collation to handle any service and here we need to install.

servicenow.itsm collection to manage service servicenow through ansible.

Install Service Now collection using below command:

$ ansible-galaxy collection install servicenow.itsm

Once the collection installed, then we have access to below modules:

  1. servicenow.itsm.incident for managing incident tickets
  2. servicenow.itsm.problem for interacting with problems
  3. servicenow.itsm.change_request for handling changes
  4. servicenow.itsm.configuration_item for managing the CMDB
  5. servicenow.itsm.now Inventory plugin and it allows us to use CMDB as an inventory source.

To display the documents of each module use below command

$ ansible-doc servicenow.itsm.incident

Credentials and Service Now declaration:

Before managing incident, we should tell ansible where our ServiceNow instance available and what credentials to be used.

Create inc_vars.yml file and mention instance & credentials as variables like below

---
#snow_record variables
sn_username: admin
sn_password: mypassword@123
sn_instance: snow_host

#data variables
sn_severity: 2
sn_priority: 2
Now that we have our credentials variables ready to use in playbook and we need to create a playbook to create new incident.

Create inc_new.yml and add below codes and save & exit

---
- host: localhost
  gather_facts: false
  tasks:
    - name: create new incident
      servicenow.itsm.incident
        state: new
        username: "{{ sn_username }}"
        password: "{{ sn_password }}"
        instance: "{{ sn_instance }}"
        
        data:
          severity: "{{ sn_severity }}"
          priority: "{{ sn_priority }}"
          short_description: demo incident
   register: new_incident
 - debug:
     var: new_incident.record
Now run this playbook using below  and it will create a new incident
#ansible-playbook inc_new.yml

Leave a Reply

Your email address will not be published. Required fields are marked *