Utilize Ansible for opening and closing tickets with ServiceNow - Part 3.

Here are links to Part 1 or Part 2

This article is part three in a series covering the role Ansible can play in ticket automation. This time we’ll cover parsing the command output data your adding to your tickets.

In the last blog we had a lot of text from the show version command end up in our ticket.

notes

We can filter this output and only record the specific data points we choose. This can be done with the ansible-network.network-engine role and custom parsers. In this blog we are going to use this specific parser show_version.yaml from the network-engine github repo.

You will structure your repo like this tree

On line 48 of show_version.yaml you can find the name of the dictionary we need to use in our debug.

system facts

example.yml

version

The parser takes the command output and creates a dictionary. The data points you want to use later in your playbook, are now parameters of system_facts.

example

What I would like to do is add some fields in the ServiceNow change_request template, then add the version and uptime to every change request Ansible creates.

In ServiceNow this is done under Configure > Form Layout.

layout

You can see below that I have added two new fields IOS Version & Device Up Time.

fields

If we take a look at a snippet of the record dictionary the ServiceNow API sends back, it now has the the two new fields. "u_device_up_time" & "u_ios_version"

api

We can use these new fields in the data section of our snow_record module. Here is a complete playbook that will run the show version command, parse the output and add the parameters into the new fields for us.

play

The new fields are now populated in our ServiceNow change request.

ticketvars

If you’re interested in learning more, stay tuned for Part 4 of this series. We will continue to build a framework for fully automating our network tickets.

TheNetwork.Engineer - July 8 2018 - Colin McCarthy

Free DevOps Resources


Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we don't like spam.