ServiceNow Inventory
Learn how to use ServiceNow CMDB as a dynamic inventory source for Ansible Automation Platform operations.
Introduction
Throughout this workshop, you’ve explored various modules from the servicenow.itsm collection for automating incident management processes. While the examples demonstrated basic automation scenarios, these modules are highly flexible and can be adapted to numerous production use cases within ITSM.
Beyond ITSM Modules
The servicenow.itsm collection provides more than just ITSM task automation. One of its most powerful features is the dynamic inventory plugin that allows you to query endpoints directly from the ServiceNow CMDB.
Dynamic Inventory Benefits
Using ServiceNow as an Ansible inventory source provides:
-
Single Source of Truth: Eliminate duplicate inventory management
-
Real-time Data: Inventory updates automatically as CMDB changes
-
Rich Metadata: Leverage all CMDB attributes for targeting and grouping
-
Compliance: Ensure automation only targets authorized systems
-
Integration: Seamless connection between ITSM and automation workflows
Inventory Architecture
The ServiceNow inventory plugin:
-
Queries CMDB: Retrieves configuration items based on filters
-
Transforms Data: Converts CI data into Ansible inventory format
-
Creates Groups: Organizes hosts by attributes (OS, manufacturer, location)
-
Provides Variables: Makes CMDB fields available as host variables
-
Updates Dynamically: Refreshes inventory data on demand
Review Inventories
Examine the current state of inventories in Automation Controller and understand the ServiceNow integration architecture.
Current Host Inventory
-
Open the Automation Controller tab
-
Navigate to Hosts in the left navigation pane
-
Observe the current host list
|
Expected Observation
The host list appears empty or contains only the lab infrastructure hosts. This is expected because:
|
Understanding the Integration
The Ansible-ServiceNow integration architecture:
-
API Integration: Direct communication between Automation Controller and ServiceNow APIs
-
No Agent Required: Target systems don’t need Ansible agents or SSH access
-
CMDB as Source: ServiceNow CMDB serves as the authoritative inventory source
-
Dynamic Updates: Inventory refreshes based on current CMDB state
Sync ServiceNow Inventory
Trigger the ServiceNow inventory synchronization to populate Automation Controller with CMDB data.
Inventory Synchronization Process
-
In Automation Controller, navigate to Inventories in the left navigation
-
Locate and click on the ServiceNow inventory
-
Select the Sources tab within the inventory details
-
Click the Sync button (🔄) to initiate synchronization
What Happens During Sync
The synchronization process triggers multiple operations:
-
API Query: Automation Controller queries ServiceNow CMDB using configured filters
-
Data Retrieval: ServiceNow returns configuration items matching the criteria
-
Data Processing: Raw CMDB data is transformed into Ansible inventory format
-
Group Creation: Hosts are organized into groups based on attributes
-
Variable Assignment: CMDB fields become available as host variables
Monitoring Sync Progress
-
Navigate to Jobs in the left navigation pane
-
Look for inventory sync jobs that were triggered
-
Monitor job progress and status
-
Review job output for any errors or warnings
The sync process may take a few minutes depending on:
-
Number of configuration items in the CMDB
-
Complexity of the inventory query
-
Network latency between systems
-
ServiceNow instance performance
Inspect Results
Examine the synchronized inventory data and understand how ServiceNow CMDB information appears in Automation Controller.
Verify Host Population
-
Once the sync jobs complete, navigate to Hosts in the left navigation
-
Observe the hosts that have been pulled from the ServiceNow CMDB
-
Note the host names, groups, and associated metadata
-
Go to Inventories → ServiceNow inventory → Hosts
-
Review the imported hosts and their properties
-
Examine the group memberships and organization
-
Click on individual hosts to see their variables and metadata
Understanding Inventory Configuration
The ServiceNow inventory uses a specific configuration that demonstrates flexible querying:
# Group hosts automatically, according to values of manufacturer and os columns.
# Include only records with the specified operating systems.
# Groups will most likely overlap.
plugin: servicenow.itsm.now
group_by:
manufacturer:
os:
includes:
- Linux Red Hat
- Windows XP
Configuration Breakdown
-
Plugin: Uses
servicenow.itsm.nowfor CMDB integration -
Filtering: Only includes specified operating systems (Linux Red Hat, Windows XP)
-
Grouping: Creates groups based on manufacturer and operating system
-
Overlapping Groups: Hosts may belong to multiple groups simultaneously
Inventory Use Cases
This dynamic inventory enables powerful automation scenarios:
Targeted Automation
-
OS-Specific Tasks: Run playbooks only on specific operating systems
-
Hardware-Based Operations: Target actions based on manufacturer or model
-
Location-Aware Automation: Execute tasks based on physical or logical location
-
Role-Based Targeting: Use business application assignments for targeting
Advanced Configuration Options
The ServiceNow inventory plugin supports numerous configuration options:
-
Custom Queries: Filter CIs using any CMDB field
-
Field Mapping: Map ServiceNow fields to Ansible variables
-
Group Creation: Define complex grouping strategies
-
Caching: Control inventory refresh frequency
-
Authentication: Various ServiceNow authentication methods
Workshop Completion
🎉 Congratulations! 🎉
You have successfully completed the ServiceNow Automation with Ansible workshop! Throughout this journey, you’ve learned to:
-
✓ Create and manage ServiceNow incidents through automation
-
✓ Implement automated problem management workflows
-
✓ Automate change request creation and tracking
-
✓ Query and update ServiceNow CMDB configuration items
-
✓ Perform automated record cleanup and maintenance
-
✓ Use ServiceNow CMDB as a dynamic Ansible inventory source
Key Takeaways
-
Integration Power: Ansible and ServiceNow provide seamless ITSM automation
-
Workflow Automation: Complex ITIL processes can be fully automated
-
Data Synchronization: Maintain consistency between systems automatically
-
Operational Efficiency: Reduce manual tasks and improve accuracy
-
Scalability: Automation scales to handle enterprise-level operations
Next Steps
To continue your ServiceNow automation journey:
-
Explore additional modules in the
servicenow.itsmcollection -
Implement custom workflows for your organization’s needs
-
Integrate ServiceNow automation with monitoring and alerting systems
-
Develop custom inventory configurations for your environment
-
Create reusable automation patterns and best practices
Troubleshooting
If you have encountered an issue or have noticed something not quite right, please open an issue on GitHub.