> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.itential.com/itential-gateway/4/servicenow-dynamic-inventory/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server. # ServiceNow dynamic inventory > Configure the ServiceNow plugin for Ansible dynamic inventory in Itential Gateway. To create and manage device inventory via plugin, several steps are required. This guide covers the ServiceNow plugin. **Related reading:** [ServiceNow inventory plugin](https://docs.ansible.com/ansible/6/collections/servicenow/servicenow/now_inventory.html#ansible-collections-servicenow-servicenow-now-inventory) #### Install the plugin There is an `ansible-galaxy` command that can install the plugin into the Gateway server. You will likely have to incorporate this command into your Gateway build plan so that you do not have to do this as a manual step. For ServiceNow the command looks like this: `ansible-galaxy collection install servicenow.servicenow` #### Configure Ansible to use the plugin There are several ways to accomplish this step. Below is a suggested method for enabling a plugin. Make sure the `interpreter_python` is appropriate for the environment. `/etc/ansible/ansible.cfg` This example enables the ServiceNow dynamic inventory plugin. ```yaml [defaults] collections_path=/opt/automation-gateway/ansible/collections:/usr/share/ansible/collections host_key_checking = False timeout = 900 # This might need adjusting depending on specifics interpreter_python = /bin/python3.9 INVENTORY_ENABLED = "servicenow.servicenow.now" [persistent_connection] command_timeout = 3600 connect_timeout = 900 ``` #### Configure the host file Use the [ServiceNow documentation](https://docs.ansible.com/ansible/6/collections/servicenow/servicenow/now_inventory.html#ansible-collections-servicenow-servicenow-now-inventory) to determine the most appropriate way to configure the plugin to connect to and query from the source of truth system. The configuration of the ServiceNow plugin below connects to the public ServiceNow, applies the filters, and returns all devices found there. Be sure to specify the host file as a `.yml` file. `/opt/automation-gateway/ansible/inventory/hosts.yml` ```yaml plugin: servicenow.servicenow.now instance: xxx username: xxx password: xxx use_extra_vars: yes table: "cmdb_ci_ip_switch" fields: - name - ip_address - manufacturer selection_order: [name] filter_results: "operational_status=1^ip_addressISNOTEMPTY^manufacturerSTARTSWITHJuniper^ORmanufacturerSTARTSWITHCisco" groups: JS: "'js' in sn_name" CS: "'cs' in sn_name" CR: "'cr' in sn_name" compose: ansible_connection: '"network_cli"' ansible_host: sn_ip_address ansible_user: '"xxx"' ansible_password: '"xxx"' ansible_port: "22" ansible_network_os: "'junos' if sn_name.startswith('js') or sn_name.startswith('jr') else 'ios' if sn_name.startswith('cs') or sn_name.startswith('cr') else 'unknown'" ``` * If using the standard table, you can remove the line `table: "cmdb_ci_ip_switch"`. * For `filter_results`, you are creating a filter based on ServiceNow rules to show the devices that you need. * For `compose: ansible_network_os`, you are using Jinja2 expressions. #### Confirm the plugin is working Before invoking the plugin from Gateway, test the plugin directly from the command line using direct Ansible capability. This command will invoke the plugin and return the devices it finds. `ansible-inventory -vvv --list -i ` #### Restart Gateway Restarting Gateway should trigger the plugin to execute. Once execution finishes, you should see Nautobot devices in the Ansible inventory. > Configure the ServiceNow plugin for Ansible dynamic inventory in Itential Gateway.