DevOps Articles

Curated articles, resources, tips and trends from the DevOps World.

Find and delete ServiceNow records en masse with the updated Ansible Conten

2 years ago www.ansible.com
Find and delete ServiceNow records en masse with the updated Ansible Conten

Summary: This is a summary of an article originally published by the source. Read the full original article here →

Have you ever had to query and remove a long list of ServiceNow records? To set up the environment, I use a demo system and another workflow to create a random user and then allow a learner to progress through some challenges using full Red Hat Ansible Automation Platform deployments and a shared ServiceNow instance.

For this reason, I recently had to develop some automation to clean up records created by these demo user accounts. Although my use-case was to clean up demo user accounts, this could just as well have been a critical ServiceNow instance that had erroneous records that needed cleaning up.

For instance, I can query and close all active incident records created by a specific user: - name: find user created incidents servicenow.itsm.incident_info: query: - sys_created_by: = {{ username }} active: = true register: incidents - name: query incident number and creation time ansible.builtin.set_fact: incident_list: '{{ incident_list + [{"number": item.number, "opened_at": item.opened_at}]}}' loop: "{{ incidents.records }}" when: incidents - name: close incidents from list servicenow.itsm.incident: state: closed number: "{{ item.number }}" close_code: "Solved (Permanently)" close_notes: "Closed with ansible servicenow.itsm" other: active: false loop: "{{ incident_list }}" when: - incident_list is defined

Made with pure grit © 2024 Jetpack Labs Inc. All rights reserved. www.jetpacklabs.com