This inventory plugin is part of the servicenow.itsm collection (version 2.7.0).
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install servicenow.itsm
.
To use it in a playbook, specify: servicenow.itsm.now
.
New in servicenow.itsm 1.0.0
- Builds inventory from ServiceNow table records.
- Requires a configuration file ending in
now.yml
ornow.yaml
. - The plugin sets host variables denoted by columns.
- For variables with dots (for example 'location.country') use lookup('ansible.builtin.vars', 'variable.name') notation. See the example section for more details. This feature is added in version 2.1.0.
Parameter |
Comments |
|
---|---|---|
aggregation boolean added in servicenow.itsm 2.7.0 |
Enable multiple variable values aggregations. Choices:
|
|
cache boolean |
Toggle to enable/disable the caching of the inventory's source data, requires a cache plugin setup to work. Choices:
Configuration:
|
|
cache_connection string |
Cache connection data or path, read cache plugin documentation for specifics. Configuration:
|
|
cache_plugin string |
Cache plugin to use for the inventory's source data. Default: Configuration:
|
|
cache_prefix string |
Prefix to use for cache plugin files/tables Default: Configuration:
|
|
cache_timeout integer |
Cache duration in seconds Default: Configuration:
|
|
columns list / elements=string |
List of table columns to be included as hostvars. Default: |
|
compose dictionary |
Create vars from jinja2 expressions. Default: |
|
enhanced boolean added in servicenow.itsm 1.3.0 |
Enable enhanced inventory which provides relationship information from CMDB. Choices:
|
|
groups dictionary |
Add hosts to group based on Jinja2 conditionals. Default: |
|
instance dictionary |
ServiceNow instance information. Default: |
|
client_id string |
ID of the client application used for OAuth authentication. If provided, it requires client_secret. Configuration:
|
|
client_secret string |
Secret associated with client_id. Used for OAuth authentication. If provided, it requires client_id. Configuration:
|
|
grant_type string added in servicenow.itsm 1.4.0 |
Grant type used for OAuth authentication. If not set, the value of the Choices:
Configuration:
|
|
host string / required |
The ServiceNow host name. Configuration:
|
|
password string / required |
Password used for authentication. Configuration:
|
|
refresh_token string added in servicenow.itsm 1.4.0 |
Refresh token used for OAuth authentication. If not set, the value of the Required when grant_type=refresh_token. Configuration:
|
|
timeout float |
Timeout in seconds for the connection with the ServiceNow instance. Configuration:
|
|
username string / required |
Username used for authentication. Configuration:
|
|
inventory_hostname_source string |
The column to use for inventory hostnames. Default: |
|
keyed_groups list / elements=dictionary |
Add hosts to group based on the values of a variable. Default: |
|
default_value string added in ansible-core 2.12 |
The default value when the host variable's value is an empty string. This option is mutually exclusive with |
|
key string |
The key from input dictionary used to generate groups |
|
parent_group string |
parent group for keyed group |
|
prefix string |
A keyed group name will start with this prefix Default: |
|
separator string |
separator used to build the keyed group name Default: |
|
trailing_separator boolean added in ansible-core 2.12 |
Set this option to This option is mutually exclusive with Choices:
|
|
leading_separator boolean added in ansible-core 2.11 |
Use in conjunction with keyed_groups. By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore. This is because the default prefix is "" and the default separator is "_". Set this option to False to omit the leading underscore (or other separator) if no prefix is given. If the group name is derived from a mapping the separator is still used to concatenate the items. To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead. Choices:
|
|
plugin string / required |
The name of the ServiceNow Inventory Plugin. This should always be Choices:
|
|
query list / elements=dictionary |
Provides a set of operators for use with filters, condition builders, and encoded queries. The data type of a field determines what operators are available for it. Refer to the ServiceNow Available Filters Queries documentation at https://docs.servicenow.com/bundle/tokyo-platform-user-interface/page/use/common-ui-elements/reference/r_OpAvailableFiltersQueries.html. Mutually exclusive with |
|
strict boolean |
If Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default. Choices:
|
|
sysparm_limit integer added in servicenow.itsm 2.5.0 |
Control the maximum number of records returned in a single query. Default: |
|
sysparm_query string added in servicenow.itsm 2.0.0 |
An encoded query string used to filter the results as an alternative to Refer to the ServiceNow Available Filters Queries documentation at https://docs.servicenow.com/bundle/tokyo-platform-user-interface/page/use/common-ui-elements/reference/r_OpAvailableFiltersQueries.html. If not set, the value of the Mutually exclusive with Configuration:
|
|
table string |
The ServiceNow table to use as the inventory source. Default: |
|
use_extra_vars boolean added in ansible-core 2.11 |
Merge extra vars into the available variables for composition (highest precedence). Choices:
Configuration:
|
- Query feature and constructed groups were added in version 1.2.0.
- Caching feature added in version 2.5.0.
# A trivial example that creates a host from every record of the
# ServiceNow cmdb_ci_server table. The ip_address column is used for
# for ansible host, and server name for inventory hostname.
# No groups will be created - all the resulting hosts are ungrouped.
plugin: servicenow.itsm.now
# `ansible-inventory -i inventory.now.yaml --graph` output:
# @all:
# |--@ungrouped:
# | |--DatabaseServer1
# | |--DatabaseServer2
# | |--INSIGHT-NY-03
# | |--MailServerUS
# | |--VMWARE-SD-04
# Group hosts automatically, according to values of the manufacturer column.
plugin: servicenow.itsm.now
keyed_groups:
- key: manufacturer
separator: ""
# `ansible-inventory -i inventory.now.yaml --graph` output:
# @all:
# |--@Dell Inc.:
# | |--DatabaseServer1
# | |--DatabaseServer2
# | |--INSIGHT-NY-03
# |--@Lenovo:
# | |--FileServerFloor1
# | |--FileServerFloor2
# |--@ungrouped:
# Group hosts automatically, according to values of the os column. Filtering ensures
# that we only see selected operating systems.
plugin: servicenow.itsm.now
query:
- os: = Linux Red Hat
- os: = Windows XP
keyed_groups:
- key: os
prefix: os
# `ansible-inventory -i inventory.now.yaml --graph` output:
# |--@os_Linux_Red_Hat:
# | |--DatabaseServer1
# | |--DatabaseServer2
# |--@os_Windows_XP:
# | |--FileServerFloor1
# | |--FileServerFloor2
# | |--INSIGHT-NY-03
# |--@ungrouped:
# Group hosts into named according to the specified criteria. Here, we created a group
# of non-Windows production servers.
plugin: servicenow.itsm.now
groups:
non_windows_prod_servers: >-
classification == "Production" and
os not in ("Windows XP", "Windows 2000", "Windows 2000 Server")
# `ansible-inventory -i inventory.now.yaml --graph` output:
# @all:
# |--@non_windows_prod_servers:
# | |--DatabaseServer2
# | |--PS LinuxApp01
# | |--PS LinuxApp02
# | |--lnux100
# | |--lnux101
# Add composed variables to hosts. In the following example, we created a cost variable
# that contains an amount and a currency, and set the ansible_host variable to the fqdn
# listed in the record.
plugin: servicenow.itsm.now
inventory_hostname_source: asset_tag
columns:
- name
- classification
- cpu_type
compose:
cost: cost ~ " " ~ cost_cc
ansible_host: fqdn
# `ansible-inventory -i inventory.now.yaml --graph --vars` output:
# @all:
# |--@ungrouped:
# | |--P1000019
# | | |--{ansible_host = my.server.com}
# | | |--{classification = Production}
# | | |--{cost = 100 USD}
# | | |--{cpu_type = Intel}
# | | |--{name = SAP-SD-02}
# Similar to the example above, but use enhanced groups with relationship information instead.
plugin: servicenow.itsm.now
enhanced: true
strict: true
inventory_hostname_source: asset_tag
columns:
- name
- classification
- cpu_type
- cost
compose:
cost: cost ~ " " ~ cost_cc
ansible_host: fqdn
# `ansible-inventory -i inventory.now.yaml --graph --vars` output:
# @all:
# |--@Blackberry_Depends_on:
# | |--P1000201
# | | |--{ansible_host = my.server.com}
# | | |--{classification = Production}
# | | |--{cost = 2,160 USD}
# | | |--{cpu_type = Intel}
# | | |--{name = INSIGHT-NY-03}
plugin: servicenow.itsm.now
enhanced: false
strict: true
table: cmdb_ci_server
columns:
- name
- ip_address
- location
- location.country
compose:
street: location
country: lookup('ansible.builtin.vars', 'location.country')
# `ansible-inventory -i inventory.now.yaml --graph --vars` output:
# @all:
# |--@ungrouped:
# | |--OWA-SD-01
# | | |--{country = Italy}
# | | |--{ip_address = }
# | | |--{location = Via Nomentana 56, Rome}
# | | |--{location.country = Italy}
# | | |--{name = OWA-SD-01}
# | | |--{street = Via Nomentana 56, Rome}
# Use a javascript function defined in ServiceNow under "Script Includes",
# which returns a list of the sys_ids that match a certain criteria
# Example of script:
# function MyFunction(key_entry) {
# var cis = [];
# var key_value = new GlideRecord("cmdb_key_value");
# key_value.addEncodedQuery("keyLIKE"+key_entry);
# key_value.query();
# while (key_value.next()) {
# cis.push(key_value.configuration_item + '');
# }
# return cis;
# }
# Other examples in https://docs.servicenow.com/bundle/tokyo-platform-user-interface/page/use/common-ui-elements/reference/r_OpAvailableFiltersQueries.html
plugin: servicenow.itsm.now
table: cmdb_ci_server
query:
- sys_id: 'IN javascript:MyFunction("xyz")'
keyed_groups:
- key: os
prefix: os
# `ansible-inventory -i inventory.now.yaml --graph` output:
# @all:
# |--@ungrouped:
# |--@os_linux:
# | |--node2
# | |--node3
# | |--node1
- Manca Bizjak (@mancabizjak)
- Miha Dolinar (@mdolin)
- Tadej Borovsak (@tadeboro)
- Uros Pascinski (@uscinski)
Hint
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.